示例#1
0
static numecoup remove_illegal_moves_by_same_king(numecoup curr, numecoup *new_top)
{
  square const sq_departure = move_generation_stack[curr].departure;

  TraceFunctionEntry(__func__);
  TraceValue("%u",curr);
  TraceSquare(sq_departure);
  TraceFunctionParamListEnd();

  while (curr<=CURRMOVE_OF_PLY(nbply)
         && move_generation_stack[curr].departure==sq_departure)
  {
    square const sq_arrival = move_generation_stack[curr].arrival;
    square const sq_capture = move_generation_stack[curr].capture;

    TraceSquare(sq_arrival);
    TraceEOL();

    if (sq_capture==kingside_castling || sq_capture==queenside_castling)
    {
      if (castlingimok(sq_departure,sq_arrival))
      {
        TraceText("accepting castling\n");
        ++*new_top;
        move_generation_stack[*new_top] = move_generation_stack[curr];
      }
    }
    else
    {
      if (are_all_imitator_arrivals_empty(sq_departure,sq_arrival))
      {
        TraceText("accepting regular move\n");
        ++*new_top;
        move_generation_stack[*new_top] = move_generation_stack[curr];
      }
    }

    ++curr;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",curr);
  TraceFunctionResultEnd();
  return curr;
}
示例#2
0
/* Try to solve in solve_nr_remaining half-moves.
 * @param si slice index
 * @note assigns solve_result the length of solution found and written, i.e.:
 *            previous_move_is_illegal the move just played is illegal
 *            this_move_is_illegal     the move being played is illegal
 *            immobility_on_next_move  the moves just played led to an
 *                                     unintended immobility on the next move
 *            <=n+1 length of shortest solution found (n+1 only if in next
 *                                     branch)
 *            n+2 no solution found in this branch
 *            n+3 no solution found in next branch
 *            (with n denominating solve_nr_remaining)
 */
void exclusive_chess_nested_exclusivity_detector_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  assert(ply_horizon<maxply);

  if (nbply>ply_horizon)
  {
    TraceText("stopping recursion");
    remember_previous_move_as_undecidable();
    solve_result = previous_move_is_illegal;
  }
  else
  {
    ply const save_ply_horizon = ply_horizon;

    exclusive_chess_undecidable_continuations[nbply] = allocate_table();

    detect_exclusivity_and_solve_accordingly(si);

    TraceValue("%u",nbply);
    TraceValue("%u",exclusive_chess_nr_continuations_reaching_goal[nbply]);
    TraceValue("%u",nr_decidable_continuations_not_reaching_goal[nbply]);
    TraceValue("%u\n",table_length(exclusive_chess_undecidable_continuations[nbply]));

    if (nr_decidable_continuations_not_reaching_goal[nbply]==0
        && exclusive_chess_nr_continuations_reaching_goal[nbply]<=1
        && table_length(exclusive_chess_undecidable_continuations[nbply])+exclusive_chess_nr_continuations_reaching_goal[nbply]>1)
      remember_previous_move_as_undecidable();

    free_table(exclusive_chess_undecidable_continuations[nbply]);

    ply_horizon = save_ply_horizon;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
示例#3
0
/* Try to solve in solve_nr_remaining half-moves.
 * @param si slice index
 * @note assigns solve_result the length of solution found and written, i.e.:
 *            previous_move_is_illegal the move just played is illegal
 *            this_move_is_illegal     the move being played is illegal
 *            immobility_on_next_move  the moves just played led to an
 *                                     unintended immobility on the next move
 *            <=n+1 length of shortest solution found (n+1 only if in next
 *                                     branch)
 *            n+2 no solution found in this branch
 *            n+3 no solution found in next branch
 *            (with n denominating solve_nr_remaining)
 */
void exclusive_chess_goal_reaching_move_counter_solve(slice_index si)
{
  unsigned int const nr_undecidable_before = table_length(exclusive_chess_undecidable_continuations[parent_ply[nbply]]);

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  pipe_solve_delegate(si);

  if (table_length(exclusive_chess_undecidable_continuations[parent_ply[nbply]])==nr_undecidable_before)
  {
    if (solve_result==MOVE_HAS_SOLVED_LENGTH())
    {
      ++exclusive_chess_nr_continuations_reaching_goal[parent_ply[nbply]];

      TraceValue("%u",nbply);
      TraceValue("%u",parent_ply[nbply]);
      TraceValue("%u\n",exclusive_chess_nr_continuations_reaching_goal[parent_ply[nbply]]);

      if (exclusive_chess_nr_continuations_reaching_goal[parent_ply[nbply]]==1)
        /* look for one more */
        solve_result = MOVE_HAS_NOT_SOLVED_LENGTH();
    }
    else if (solve_result==MOVE_HAS_NOT_SOLVED_LENGTH())
    {
      ++nr_decidable_continuations_not_reaching_goal[parent_ply[nbply]];
      TraceText("remembering defined continuation");
      TraceValue("%u",nbply);
      TraceValue("%u",parent_ply[nbply]);
      TraceValue("%u\n",nr_decidable_continuations_not_reaching_goal[parent_ply[nbply]]);
    }
  }
  else if (solve_result==MOVE_HAS_SOLVED_LENGTH())
    solve_result = MOVE_HAS_NOT_SOLVED_LENGTH();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}