Ejemplo n.º 1
0
static boolean is_mover_supported(numecoup n)
{
  square const sq_departure = move_generation_stack[n].departure;
  boolean result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  if (is_in_chain[sq_departure])
    result = false;
  else
  {
    is_in_chain[sq_departure] = true;

    siblingply(trait[nbply]);
    push_observation_target(sq_departure);

    result = is_mover_supported_recursive();

    finply();

    is_in_chain[sq_departure] = false;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Ejemplo n.º 2
0
static void PushMagicViews(void)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  magic_views_top[stack_pointer] = magic_views_top[stack_pointer-1];

  siblingply(no_side);
  push_observation_target(initsquare);
  prev_observation_context[nbply] = observation_context;

  are_we_finding_magic_views[nbply] = true;

  PushMagicViewsByOneSide(White);
  PushMagicViewsByOneSide(Black);

  are_we_finding_magic_views[nbply] = false;

  /* TODO: remove double views by neutral magic pieces
   * apply same logic as for cross-eyed pieces? */

  finply();

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

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Ejemplo n.º 3
0
static boolean is_not_king_captures_guarded_king(numecoup n)
{
    square const sq_observer = move_generation_stack[CURRMOVE_OF_PLY(nbply)].departure;
    square const sq_observee = move_generation_stack[CURRMOVE_OF_PLY(nbply)].capture;
    boolean result;

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

    if (TSTFLAG(being_solved.spec[sq_observer],Royal) && TSTFLAG(being_solved.spec[sq_observee],Royal))
    {
        siblingply(advers(trait[nbply]));
        push_observation_target(move_generation_stack[n].capture);
        result = !is_square_observed(EVALUATE(observer));
        finply();
    }
    else
        result = true;

    TraceFunctionExit(__func__);
    TraceFunctionResult("%u",result);
    TraceFunctionResultEnd();
    return result;
}
Ejemplo n.º 4
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 mummer_orchestrator_solve(slice_index si)
{
  ply const save_nbply = nbply;

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

  mum_length[parent_ply[nbply]] = INT_MIN;
  reset_accepted_moves(nbply);

  copyply();
  move_generator_invert_move_order(nbply);
  fork_solve_delegate(si);
  finply();

  /* in some very obscure situations (cf. bug #142), we would continue with
   * e.g. knight promotion if queen promotion was played while measuring lengths
   */
  ++post_move_iteration_id[nbply];

  nbply = save_nbply;
  SET_CURRMOVE(nbply,last_candidate[nbply]);

  pipe_solve_delegate(si);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Ejemplo n.º 5
0
static boolean is_kingsquare_observed(void)
{
  Side const side = trait[nbply];
  boolean result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  if (transmuting_kings_testing_transmutation[side])
    result = false;
  else
  {
    transmuting_kings_testing_transmutation[side] = true;

    siblingply(advers(side));
    push_observation_target(being_solved.king_square[side]);
    result = fork_is_square_observed_nested_delegate(temporary_hack_is_square_observed[side],
                                                     EVALUATE(observation));
    finply();

    transmuting_kings_testing_transmutation[side] = false;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Ejemplo n.º 6
0
/* Determine whether the moving side's king is transmuting as a specific walk
 * @param p the piece
 */
boolean transmuting_kings_is_king_transmuting_as(piece_walk_type walk)
{
  boolean result;
  Side const side_attacking = trait[nbply];

  TraceFunctionEntry(__func__);
  TraceWalk(walk);
  TraceFunctionParamListEnd();

  if (transmuting_kings_testing_transmutation[side_attacking])
    result = false;
  else
  {
    transmuting_kings_testing_transmutation[side_attacking] = true;

    siblingply(advers(side_attacking));
    push_observation_target(being_solved.king_square[side_attacking]);
    observing_walk[nbply] = walk;
    result = fork_is_square_observed_nested_delegate(temporary_hack_is_square_observed_specific[trait[nbply]],
                                                     EVALUATE(observation));
    finply();

    transmuting_kings_testing_transmutation[side_attacking] = false;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Ejemplo n.º 7
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 retro_start_retro_move_ply(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  /* Make sure that trait is the opposite of the first move (or there
   * will be no e.p. capture). */
  assert(slices[si].starter!=no_side);
  nextply(advers(slices[si].starter));

  assert(nbply==ply_retro_move);

  {
    /* TODO let Mars Circe or SingleBox Type 3 add slices here that do this */
    unsigned int i;
    for (i = 0; i!=move_effect_journal_index_offset_capture; ++i)
      move_effect_journal_do_null_effect();
  }

  pipe_solve_delegate(si);

  undo_move_effects();

  finply();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Ejemplo n.º 8
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 move_generator_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  nextply(SLICE_STARTER(si));
  genmove();
  pipe_solve_delegate(si);
  finply();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Ejemplo n.º 9
0
static boolean find_flights(slice_index si,
                            Side side_in_check,
                            unsigned int nr_flights_to_find)
{
  unsigned int nr_flights_found = 0;
  square const save_king_square = being_solved.king_square[side_in_check];
  piece_walk_type const king_walk = get_walk_of_piece_on_square(save_king_square);
  Flags const king_flags = being_solved.spec[save_king_square];
  square const save_departure = curr_generation->departure ;

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

  siblingply(side_in_check);

  curr_generation->departure = save_king_square;
  move_generation_current_walk = king_walk;
  generate_moves_for_piece_based_on_walk();

  empty_square(save_king_square);

  while (encore())
  {
    being_solved.king_square[side_in_check] = move_generation_stack[CURRMOVE_OF_PLY(nbply)].arrival;
    if ((is_square_empty(being_solved.king_square[side_in_check])
         || TSTFLAG(being_solved.spec[being_solved.king_square[side_in_check]],advers(side_in_check)))
        && being_solved.king_square[side_in_check]!=being_solved.king_square[advers(side_in_check)]
        && !pipe_is_in_check_recursive_delegate(si,side_in_check))
      ++nr_flights_found;

    pop_move();
  }

  being_solved.king_square[side_in_check] = save_king_square;
  occupy_square(save_king_square,king_walk,king_flags);

  curr_generation->departure = save_departure;

  finply();

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",nr_flights_found>nr_flights_to_find);
  TraceFunctionResultEnd();
  return nr_flights_found>nr_flights_to_find;
}
Ejemplo n.º 10
0
static boolean is_mover_supported(numecoup n)
{
  boolean result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  siblingply(trait[nbply]);
  push_observation_target(move_generation_stack[n].departure);
  result = is_square_observed(EVALUATE(observer));
  finply();

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Ejemplo n.º 11
0
static boolean is_target_unguarded(numecoup n)
{
  boolean result;

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

  siblingply(advers(trait[nbply]));
  push_observation_target(move_generation_stack[n].capture);
  result = !is_square_observed(EVALUATE(observer));
  finply();

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Ejemplo n.º 12
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 retro_start_retraction_ply(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  nextply(no_side);
  assert(nbply==ply_retro_move_takeback);

  pipe_solve_delegate(si);

  undo_move_effects();

  finply();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Ejemplo n.º 13
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 take_and_make_generate_make_solve(slice_index si)
{
  numecoup const take_top = CURRMOVE_OF_PLY(nbply);
  numecoup take_current = MOVEBASE_OF_PLY(nbply)+1;
  Side const moving = trait[nbply];

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

  siblingply(advers(moving)); /* generate according to the taken piece's side */

  for (; take_current<=take_top; ++take_current)
  {
    square const take_capture = move_generation_stack[take_current].capture;
    if (en_passant_is_ep_capture(take_capture))
      generate_make_for_one_take(take_current,
                                 take_capture-offset_en_passant_capture);
    else if (get_walk_of_piece_on_square(take_capture)==Empty)
      push_move_copy(take_current);
    else
      generate_make_for_one_take(take_current,take_capture);
  }

  trait[nbply] = moving; /* move on behalf of to the taking piece's side */

  pipe_solve_delegate(si);

  finply();

  /* prevent the current take generation from disturbing if we generate more
   * moves in the current ply, e.g. while testing for immobility of a side
   */
  pop_all();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}