Beispiel #1
0
static boolean are_all_imitator_lines_clear(numvec diff_first_necessarily_empty,
                                            numvec step,
                                            numvec diff_first_not_necessarily_empty)
{
  boolean result = true;
  unsigned int i;

  TraceFunctionEntry(__func__);
  TraceValue("%d",diff_first_necessarily_empty);
  TraceValue("%d",step);
  TraceValue("%d",diff_first_not_necessarily_empty);
  TraceFunctionParamListEnd();

  TraceValue("%u\n",being_solved.number_of_imitators);

  for (i = 0; i!=being_solved.number_of_imitators; ++i)
    if (!is_imitator_line_clear(i,diff_first_necessarily_empty,step,diff_first_not_necessarily_empty))
    {
      result = false;
      break;
    }

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
/* 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 goalreachable_guard_mate_solve(slice_index si)
{
  Side const just_moved = advers(SLICE_STARTER(si));

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

  --MovesLeft[just_moved];
  TraceEnumerator(Side,SLICE_STARTER(si));
  TraceEnumerator(Side,just_moved);
  TraceValue("%u",MovesLeft[SLICE_STARTER(si)]);
  TraceValue("%u",MovesLeft[just_moved]);
  TraceEOL();

  pipe_this_move_doesnt_solve_if(si,!mate_isGoalReachable());

  ++MovesLeft[just_moved];
  TraceValue("%u",MovesLeft[SLICE_STARTER(si)]);
  TraceValue("%u",MovesLeft[just_moved]);
  TraceEOL();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #3
0
/* Start a new ply as a sibling of the current ply, making the child the new
 * current ply
 * @param side the side at the move in the child ply
 */
void siblingply(Side side)
{
  ply const elder = nbply;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  assert(ply_watermark<maxply);

  ply_stack[ply_stack_pointer++] = nbply;
  nbply = ply_watermark+1;
  current_move[nbply] = current_move[ply_watermark];
  current_move_id[nbply] = current_move_id[ply_watermark];
  ++ply_watermark;

  TraceValue("%u",elder);
  TraceValue("%u",nbply);
  TraceEOL();

  parent_ply[nbply] = parent_ply[elder];

  trait[nbply] = side;

  move_effect_journal_base[nbply+1] = move_effect_journal_base[nbply];
  en_passant_top[nbply] = en_passant_top[nbply-1];
  promotion_horizon[nbply] = move_effect_journal_base[nbply];

  post_move_iteration_init_ply();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
/* Iterate if square observation testing uses a post-move iterating slice (e.g.
 * for MarsCirce Super)
 * @param si identifies move generator slice
 */
void square_observation_post_move_iterator_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  ++current_level;
  TraceValue("%u",current_level);TraceEOL();

  if (current_level>iteration_level)
  {
    iteration_level = current_level;
    TraceValue("%u",iteration_level);TraceValue("%u",current_level);TraceEOL();
  }

  do
  {
    pipe_is_square_observed_delegate(si);
  } while (iteration_level>current_level && !observation_result);

  --current_level;
  TraceValue("%u",current_level);TraceEOL();

  post_move_iteration_cancel();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #5
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();
}
Beispiel #6
0
static void PushMagicView(square pos_viewed, square pos_magic, square start, square end)
{
  unsigned int const top = magic_views_top[stack_pointer];

  TraceFunctionEntry(__func__);
  TraceSquare(pos_viewed);
  TraceSquare(pos_magic);
  TraceSquare(start);
  TraceSquare(end);
  TraceFunctionParamListEnd();

  assert(magic_views_top[stack_pointer]<magicviews_size);

  magicviews[top].pos_viewed = pos_viewed;
  magicviews[top].viewedid = GetPieceId(being_solved.spec[pos_viewed]);
  magicviews[top].magicpieceid = GetPieceId(being_solved.spec[pos_magic]);
  magicviews[top].line_start = start;
  magicviews[top].line_end = end;
  ++magic_views_top[stack_pointer];

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

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #7
0
static void remember_previous_move_as_undecidable(void)
{
  append_to_table(exclusive_chess_undecidable_continuations[parent_ply[nbply]]);
  TraceValue("%u",nbply);
  TraceValue("%u",parent_ply[nbply]);
  TraceValue("%u\n",table_length(exclusive_chess_undecidable_continuations[parent_ply[nbply]]));
}
Beispiel #8
0
static boolean is_imitator_line_clear(unsigned int i,
                                      numvec diff_first_necessarily_empty,
                                      numvec step,
                                      numvec diff_first_not_necessarily_empty)
{
  boolean result = true;
  square const sq_first_not_necessarily_empty = being_solved.isquare[i]+diff_first_not_necessarily_empty;
  square sq_curr;

  TraceFunctionEntry(__func__);
  TraceValue("%u",i);
  TraceValue("%d",diff_first_necessarily_empty);
  TraceValue("%d",step);
  TraceValue("%d",diff_first_not_necessarily_empty);
  TraceFunctionParamListEnd();

  for (sq_curr = being_solved.isquare[i]+diff_first_necessarily_empty; sq_curr!=sq_first_not_necessarily_empty; sq_curr += step)
  {
    TraceSquare(sq_curr);TraceEOL();
    if (!is_square_empty(sq_curr))
    {
      result = false;
      break;
    }
  }

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Beispiel #9
0
static void substitute_deadend_goal(slice_index si, stip_moves_traversal *st)
{
  optimisation_state * const state = st->param;
  slice_index const save_optimisable_deadend = state->optimisable_deadend;

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

  stip_traverse_moves_children(si,st);

  TraceValue("%u",state->optimisable_deadend);
  TraceValue("%u",state->end_of_branch_goal);
  TraceValue("%u\n",st->context);
  if (state->optimisable_deadend!=no_slice
      && state->end_of_branch_goal!=no_slice
      && st->context!=stip_traversal_context_attack)
  {
    slice_index const prototype = alloc_pipe(STDeadEndGoal);
    defense_branch_insert_slices(si,&prototype,1);
    pipe_remove(state->optimisable_deadend);
  }

  state->optimisable_deadend = save_optimisable_deadend;

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #10
0
/* Determine whether a specific piece delivers check to a specific side
 * @param observer_origin potentially delivering check ...
 * @note the piece on pos_checking must belong to advers(side)
 * @note sets observation_result
 */
void marscirce_is_square_observed(slice_index si)
{
  circe_rebirth_context_elmt_type * const context = &circe_rebirth_context_stack[circe_rebirth_context_stack_pointer-1];
  square const sq_target = move_generation_stack[CURRMOVE_OF_PLY(nbply)].capture;

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

  assert(circe_rebirth_context_stack_pointer>0);

  observation_result = false;

  if (observing_walk[nbply]<Queen || observing_walk[nbply]>Bishop
      || CheckDir[observing_walk[nbply]][sq_target-context->rebirth_square]!=0)
  {
    if (is_square_empty(context->rebirth_square))
    {
      TraceSquare(context->rebirth_square);
      TraceWalk(context->reborn_walk);
      TraceValue("%u",TSTFLAG(being_solved.spec[context->rebirth_square],White));
      TraceValue("%u",TSTFLAG(being_solved.spec[context->rebirth_square],Black));
      TraceEOL();
      occupy_square(context->rebirth_square,context->reborn_walk,context->reborn_spec);
      pipe_is_square_observed_delegate(si);
      empty_square(context->rebirth_square);
    }
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #11
0
/* Plan optimising away a STOhneschachStopIfCheckAndNotMate slice
 * @param stop identifies STOhneschachStopIfCheckAndNotMate slice
 * @param to_be_optimised true iff stop is going to be optimised away
 */
void ohneschach_stop_if_check_plan_to_optimise_away_stop(slice_index stop,
                                                         boolean to_be_optimised)
{
  slice_index const immobility_tester = SLICE_NEXT2(stop);

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",stop);
  TraceFunctionParam("%u",to_be_optimised);
  TraceFunctionParamListEnd();

  TraceValue("%u",fate[immobility_tester]);
  TraceEOL();

  if (to_be_optimised)
  {
    fate[stop] = fate_stop_to_be_optimised;
    if (fate[immobility_tester]==fate_dont_know)
      fate[immobility_tester] = fate_immobility_tester_obsolete;
  }
  else
  {
    fate[stop] = fate_stop_not_to_be_optimised;
    fate[immobility_tester] = fate_immobility_tester_still_used;
  }

  TraceValue("->%u",fate[immobility_tester]);
  TraceEOL();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #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 imitator_pawn_promoter_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  {
    square sq_arrival;
    Side as_side;

    find_potential_promotion_square(promotion_horizon[nbply],&sq_arrival,&as_side);

    assert(stack_pointer<stack_size);

    if (post_move_iteration_id[nbply]!=prev_post_move_iteration_id[stack_pointer])
      promotion_into_imitator[stack_pointer] = is_square_occupied_by_promotable_pawn(sq_arrival,as_side);

    TraceValue("%u",post_move_iteration_id[nbply]);
    TraceValue("%u",prev_post_move_iteration_id[stack_pointer]);
    TraceValue("%u\n",promotion_into_imitator[stack_pointer]);

    if (promotion_into_imitator[stack_pointer])
    {
      move_effect_journal_index_type const save_horizon = promotion_horizon[nbply];

      promotion_horizon[nbply] = move_effect_journal_base[nbply+1];

      move_effect_journal_do_piece_removal(move_effect_reason_pawn_promotion,
                                           sq_arrival);
      move_effect_journal_do_imitator_addition(move_effect_reason_pawn_promotion,
                                               sq_arrival);

      ++stack_pointer;
      fork_solve_delegate(si);
      --stack_pointer;

      promotion_horizon[nbply] = save_horizon;

      TraceValue("%u\n",post_move_iteration_locked[nbply]);
      if (!post_move_iteration_locked[nbply])
      {
        promotion_into_imitator[stack_pointer] = false;
        lock_post_move_iterations();
      }
    }
    else
    {
      ++stack_pointer;
      pipe_solve_delegate(si);
      --stack_pointer;
    }

    prev_post_move_iteration_id[stack_pointer] = post_move_iteration_id[nbply];
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #13
0
/* Lock post move iterations in the current move retraction
 */
void lock_post_move_iterations(void)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  post_move_iteration_locked[nbply] = true;
  ++post_move_iteration_id[nbply];
  TraceValue("%u",nbply);TraceValue("%u\n",post_move_iteration_id[nbply]);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
boolean post_move_iteration_ply_was_ended(void)
{
  boolean result = iteration_level==current_level;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  TraceValue("%u",iteration_level);TraceValue("%u",current_level);TraceEOL();

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
/* Determine whether the current post move iteration participant has the lock
 * @param true iff it has
 */
boolean post_move_have_i_lock(void)
{
  boolean const result = iteration_level==current_level+1;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  TraceValue("%u",iteration_level);TraceValue("%u",current_level);TraceEOL();

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
void post_move_iteration_init_ply(void)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  TraceValue("%u",current_level);TraceEOL();

  iteration_level = current_level;

  TraceValue("%u",iteration_level);TraceEOL();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #17
0
/* @return true iff >=1 black pieces needed to be immobilised
 */
boolean intelligent_stalemate_immobilise_black(void)
{
    boolean result = false;
    immobilisation_state_type immobilisation_state = null_state;
    castling_rights_type const save_castling_flag = being_solved.castling_rights;

    TraceFunctionEntry(__func__);
    TraceFunctionParamListEnd();

    /* we temporarily disable Black castling for two reasons:
     * 1. we are solving from the target position here where king or rook may be
     *    at different positions than in the diagram; attempting to generate
     *    (let alone) execute castling moves would cause problems in this case
     * 2. castlings are presumable never the only legal black moves
     */
    CLRCASTLINGFLAGMASK(Black,k_cancastle);
    current_state = &immobilisation_state;

    conditional_pipe_solve_delegate(current_start_slice);

    next_trouble_maker();
    current_state = 0;
    being_solved.castling_rights = save_castling_flag;

    if (immobilisation_state.worst.requirement>no_requirement)
    {
        assert(immobilisation_state.worst.target_square!=initsquare);

        TraceSquare(immobilisation_state.worst.target_square);
        TraceValue("%u",immobilisation_state.worst.requirement);
        TraceValue("%u\n",immobilisation_state.worst.nr_flight_directions);

        if (immobilisation_state.worst.requirement<immobilisation_impossible)
        {
            intelligent_stalemate_pin_black_piece(immobilisation_state.worst.target_square);

            if (immobilisation_state.worst.requirement<pin_required
                    && can_we_block_all_necessary_squares(&immobilisation_state.worst))
                block_squares(&immobilisation_state.worst);
        }

        result = true;
    }

    TraceFunctionExit(__func__);
    TraceFunctionResult("%u",result);
    TraceFunctionResultEnd();
    return result;
}
/* Iterate if move generation uses a post-move iterating slice (e.g. for
 * MarsCirce Super)
 * @param si identifies move generator slice
 */
void move_generation_post_move_iterator_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  do
  {
    pipe_move_generation_delegate(si);
    TraceValue("%u",iteration_level);TraceValue("%u",current_level);TraceEOL();
  } while (iteration_level>current_level);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
void post_move_iteration_end(void)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  TraceValue("%u",iteration_level);TraceValue("%u",current_level);TraceEOL();

  assert(iteration_level==current_level+1);
  --iteration_level;

  TraceValue("%u",iteration_level);TraceValue("%u",current_level);TraceEOL();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #20
0
/* Determine whether a side observes a specific square
 * @param si identifies the tester slice
 * @note sets observation_result
 */
void marscirce_iterate_observers(slice_index si)
{
  circe_rebirth_context_elmt_type * const context = &circe_rebirth_context_stack[circe_rebirth_context_stack_pointer];
  Side const side_observing = trait[nbply];
  square const *observer_origin;
  square const sq_target = move_generation_stack[CURRMOVE_OF_PLY(nbply)].capture;

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

  observation_result = false;

  context->relevant_ply = nbply;

  for (observer_origin = boardnum; *observer_origin; ++observer_origin)
    if (*observer_origin!=sq_target /* no auto-observation */
        && TSTFLAG(being_solved.spec[*observer_origin],side_observing)
        && get_walk_of_piece_on_square(*observer_origin)==observing_walk[nbply])
    {
      context->rebirth_from = *observer_origin;
      context->reborn_walk = observing_walk[nbply];
      context->reborn_spec = being_solved.spec[context->rebirth_from];
      context->relevant_side = advers(side_observing);
      context->relevant_square = context->rebirth_from;

      pipe_is_square_observed_delegate(si);

      if (observation_result)
        break;
    }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #21
0
/* iterate until we detect an input token that identifies the user's language
 * @return the detected language
 */
static Language detect_user_language(char *tok)
{
  Language result = LanguageCount;

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%s",tok);
  TraceFunctionParamListEnd();

  {
    Language candidate;
    for (candidate = 0; candidate<LanguageCount; ++candidate)
    {
      TraceValue("%u",candidate);TraceEOL();
      if (GetUniqIndex(GlobalTokenCount,GlobalTokenString[candidate],tok)==BeginProblem)
      {
        result = candidate;
        break;
      }
    }
  }

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Beispiel #22
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 goal_doublemate_reached_tester_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  TraceValue("%u",nbply);
  TraceValue("%u",parent_ply[nbply]);
  TraceEOL();
  pipe_this_move_doesnt_solve_if(si,
                                 !TSTFLAG(goal_preprequisites_met[parent_ply[nbply]],
                                          goal_doublemate));

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #23
0
static numecoup remove_illegal_moves_by_same_mao(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_hurdle = hoppper_moves_auxiliary[move_generation_stack[curr].id].sq_hurdle;

    if (are_all_imitator_arrivals_empty(sq_departure,sq_hurdle)
        && are_all_imitator_arrivals_empty(sq_departure,sq_arrival))
    {
      ++*new_top;
      move_generation_stack[*new_top] = move_generation_stack[curr];
    }

    ++curr;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",curr);
  TraceFunctionResultEnd();
  return curr;
}
Beispiel #24
0
static char *ParseLength(char *tok, stip_length_type *length)
{
    char *end;
    unsigned long tmp_length;

    TraceFunctionEntry(__func__);
    TraceFunctionParam("%s",tok);
    TraceFunctionParamListEnd();

    if (tok!=0 && *tok==0)
        /* allow white space before length, e.g. "dia 4" */
        tok = ReadNextTokStr();

    tmp_length = strtoul(tok,&end,10);
    TraceValue("%ld",tmp_length);
    TraceEOL();

    if (tok==end || tmp_length>UINT_MAX)
    {
        output_plaintext_input_error_message(WrongInt,0);
        tok = 0;
    }
    else
    {
        *length = tmp_length;
        tok = end;
    }

    TraceFunctionExit(__func__);
    TraceFunctionResult("%s",tok);
    TraceFunctionResultEnd();
    return tok;
}
Beispiel #25
0
static void stip_traverse_moves_defense_adapter(slice_index si,
                                                stip_moves_traversal *st)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  if (st->context==stip_traversal_context_intro)
  {
    assert(st->remaining==STIP_MOVES_TRAVERSAL_LENGTH_UNINITIALISED);
    assert(st->full_length==STIP_MOVES_TRAVERSAL_LENGTH_UNINITIALISED);
    st->full_length = SLICE_U(si).branch.length-slack_length;
    TraceValue("->%u",st->full_length);
    TraceEOL();
    st->remaining = st->full_length;
    st->context = stip_traversal_context_defense;

    stip_traverse_moves_pipe(si,st);

    st->context = stip_traversal_context_intro;
    st->remaining = STIP_MOVES_TRAVERSAL_LENGTH_UNINITIALISED;
    st->full_length = STIP_MOVES_TRAVERSAL_LENGTH_UNINITIALISED;
  }
  else
    stip_traverse_moves_pipe(si,st);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #26
0
static void insert_separator(slice_index si, stip_structure_traversal *st)
{
  TraceFunctionEntry(__func__);
  TraceValue("%u",si);
  TraceFunctionParamListEnd();

  stip_traverse_structure_children(si,st);

  {
    slice_index const proxy_standard = alloc_proxy_slice();
    slice_index const standard = alloc_pipe(STMoveForPieceGeneratorStandardPath);

    slice_index const proxy_alternative = alloc_proxy_slice();
    slice_index const alternative = alloc_pipe(STMoveForPieceGeneratorAlternativePath);

    slice_index const generator = alloc_binary_slice(STMoveForPieceGeneratorTwoPaths,
                                                     proxy_standard,
                                                     proxy_alternative);

    pipe_link(SLICE_PREV(si),generator);

    pipe_link(proxy_standard,standard);
    pipe_link(standard,si);

    pipe_link(proxy_alternative,alternative);
    pipe_link(alternative,si);
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #27
0
/* (Approximately) depth-first traversl of the stipulation
 * @param root start of the stipulation (sub)tree
 * @param st address of data structure holding parameters for the operation
 */
void stip_traverse_moves(slice_index root, stip_moves_traversal *st)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",root);
  TraceFunctionParam("%p",st);
  TraceFunctionParamListEnd();

  TraceValue("%u",st->remaining);
  TraceEOL();

  TraceEnumerator(slice_type,SLICE_TYPE(root));
  TraceEOL();
  assert(SLICE_TYPE(root)<=nr_slice_types);

  if (st->remaining_watermark[root]<=st->remaining)
  {
    stip_moves_visitor const operation = st->map.visitors[SLICE_TYPE(root)];
    assert(operation!=0);
    (*operation)(root,st);
    st->remaining_watermark[root] = st->remaining+1;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #28
0
/* Produce slices representing set play.
 * This is supposed to be invoked from within the slice type specific
 * functions invoked by stip_apply_setplay.
 * @param adapter identifies the adapter slice into the battle branch
 * @param state address of structure holding state
 */
void battle_branch_make_setplay(slice_index adapter, spin_off_state_type *state)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",adapter);
  TraceFunctionParamListEnd();

  {
    slice_index const start = branch_find_slice(STReadyForDefense,
                                                adapter,
                                                stip_traversal_context_intro);
    stip_structure_traversal st;

    slice_index const notend = branch_find_slice(STNotEndOfBranchGoal,
                                                 adapter,
                                                 stip_traversal_context_intro);
    slice_index const prototype = alloc_pipe(STEndOfRoot);
    assert(notend!=no_slice);
    defense_branch_insert_slices(notend,&prototype,1);

    assert(start!=no_slice);

    stip_structure_traversal_init(&st,state);
    st.context = stip_traversal_context_defense;
    stip_structure_traversal_override_by_structure(&st,
                                                   slice_structure_pipe,
                                                   &copy_to_setplay);
    stip_structure_traversal_override_by_structure(&st,
                                                   slice_structure_branch,
                                                   &copy_to_setplay);
    stip_structure_traversal_override_by_structure(&st,
                                                   slice_structure_fork,
                                                   &copy_to_setplay);
    stip_structure_traversal_override_single(&st,STEndOfRoot,&serve_as_root_hook);
    stip_traverse_structure(start,&st);
    TraceValue("%u",state->spun_off[start]);
    TraceEOL();
    state->spun_off[adapter] = state->spun_off[start];
  }

  TraceValue("%u",state->spun_off[adapter]);
  TraceEOL();

  TraceFunctionExit(__func__);
  TraceFunctionParamListEnd();
}
Beispiel #29
0
static void forget_deadend(slice_index si, stip_moves_traversal *st)
{
  optimisation_state * const state = st->param;
  slice_index const save_optimisable_deadend = state->optimisable_deadend;

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

  TraceValue("%u\n",state->optimisable_deadend);
  stip_traverse_moves_children(si,st);
  TraceValue("%u\n",state->optimisable_deadend);
  state->optimisable_deadend = save_optimisable_deadend;
  TraceValue("->%u\n",state->optimisable_deadend);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
/* 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_execution_post_move_iterator_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  TraceValue("%u",iteration_level);TraceValue("%u",current_level);TraceEOL();

  pipe_solve_delegate(si);

  TraceValue("%u",iteration_level);TraceValue("%u",current_level);TraceEOL();

  if (iteration_level==current_level)
    pop_move();

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}