Beispiel #1
0
static void write_series(slice_index si, stip_structure_traversal *st)
{
  state_type * const state = st->param;

  if (st->level==structure_traversal_level_top
      && state->length>slack_length+2
      && SLICE_U(si).branch.min_length>=state->length-1)
    state->nr_chars_written += fprintf(state->file,"%s","exact-");

  if (is_intro_series(si))
  {
    if (state->length%2==1)
      state->nr_chars_written += fprintf(state->file,"%u",(state->length+1)/2);
    else if (state->length>1)
      state->nr_chars_written += fprintf(state->file,"%u",state->length/2);
    state->nr_chars_written += fprintf(state->file,"%s","->");
    stip_traverse_structure_children(si,st);
  }
  else
  {
    state->nr_chars_written += fprintf(state->file,"%s", "ser-");

    if (is_help_reci(si))
    {
      state->nr_chars_written += fprintf(state->file,"%s", "reci-h");
      state->length += 2;
    }

    stip_traverse_structure_children(si,st);
    if (state->length%2==1)
      state->nr_chars_written += fprintf(state->file,"%u",(state->length+1)/2);
    else if (state->length>1)
      state->nr_chars_written += fprintf(state->file,"%u",state->length/2);
  }
}
Beispiel #2
0
static void substitute_self_check_guard(slice_index si, stip_structure_traversal *st)
{
  insertion_state_type * const state = st->param;

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

  if (state->are_we_counting_goal_reaching_moves)
  {
    state->are_we_counting_goal_reaching_moves = false;
    stip_traverse_structure_children(si,st);
    state->are_we_counting_goal_reaching_moves = true;

    {
      slice_index const guard = branch_find_slice(STSelfCheckGuard,SLICE_NEXT2(si),st->context);
      if (guard!=no_slice)
      {
        slice_index const prototype = alloc_pipe(STExclusiveChessGoalReachingMoveCounterSelfCheckGuard);
        goal_branch_insert_slices(SLICE_NEXT2(si),&prototype,1);
        st->traversed[guard] = slice_not_traversed;
        pipe_remove(guard);
      }
    }
  }
  else
    stip_traverse_structure_children(si,st);

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

  if (SLICE_STARTER(si)==Black)
  {
    slice_index * const landing = st->param;
    slice_index const save_landing = *landing;

    *landing = no_slice;
    insert_landing(si,st);

    stip_traverse_structure_children(si,st);

    insert_null_move_handler(si,st);
    *landing = save_landing;

    {
      slice_index const prototype = alloc_pipe(STBlackChecks);
      move_insert_slices(si,st->context,&prototype,1);
    }
  }
  else
    stip_traverse_structure_children(si,st);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #4
0
static void write_help(slice_index si, stip_structure_traversal *st)
{
  state_type * const state = st->param;

  if (state->reci_goal.type!=no_goal)
    stip_traverse_structure_children(si,st);
  else
  {
    if (st->level==structure_traversal_level_top
        && state->length>slack_length+2
        && SLICE_U(si).branch.min_length>=state->length-1)
      state->nr_chars_written += fprintf(state->file,"%s","exact-");

    if (is_help_reci(si))
    {
      state->nr_chars_written += fprintf(state->file,"%s", "reci-");
      state->length += 2;
    }

    if (is_pser(si,st))
    {
      if (branch_find_slice(STEndOfBranchGoal,si,stip_traversal_context_help)!=no_slice
          || branch_find_slice(STEndOfBranchGoalImmobile,si,stip_traversal_context_help)!=no_slice)
      {
        state->nr_chars_written += fprintf(state->file,"%s","phser-");
        ++state->length;
      }
      else if (branch_find_slice(STEndOfBranchForced,si,stip_traversal_context_help)!=no_slice)
        state->nr_chars_written += fprintf(state->file,"%s","phser-");
      else
      {
        state->nr_chars_written += fprintf(state->file,"%s","pser-");
        ++state->length;
      }
    }
    else if (!is_help_play_implicit(si,st))
      state->nr_chars_written += fprintf(state->file,"%s", "h");

    stip_traverse_structure_children(si,st);

    if (st->level==structure_traversal_level_top)
    {
      state->nr_chars_written += fprintf(state->file,"%u",state->length/2);
      if (state->length%2==1)
        state->nr_chars_written += fprintf(state->file,"%s",".5");
    }
    else
    {
      /* h part of a ser-h - no need to write length */
    }
  }
}
Beispiel #5
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();
}
static void instrument_move(slice_index si, stip_structure_traversal *st)
{
  insertion_state const * const state = st->param;

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

  stip_traverse_structure_children(si,st);

  if (state->own_king_capture_possible==twin_id)
  {
    slice_index const prototype = alloc_pipe(STOwnKingCaptureAvoider);
    move_insert_slices(si,st->context,&prototype,1);
  }

  if (state->opponent_king_capture_possible==twin_id)
  {
    slice_index const prototype = alloc_pipe(STOpponentKingCaptureAvoider);
    move_insert_slices(si,st->context,&prototype,1);
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #7
0
static void write_attack(slice_index si, stip_structure_traversal *st)
{
  state_type * const state = st->param;
  stip_length_type const save_length = state->length;
  structure_traversal_level_type const save_level = state->branch_level;;

  state->branch_level = st->level;
  state->length = SLICE_U(si).branch.length;

  if (st->level==structure_traversal_level_top
      && state->length>slack_length+2
      && SLICE_U(si).branch.min_length==state->length-1)
    state->nr_chars_written += fprintf(state->file,"%s","exact-");

  if (is_pser(si,st))
    state->nr_chars_written += fprintf(state->file,"%s","pser-");

  stip_traverse_structure_children(si,st);

  if (st->level==structure_traversal_level_top)
    state->nr_chars_written += fprintf(state->file,
                                                "%u",
                                                (SLICE_U(si).branch.length+1)/2);

  state->length = save_length;
  state->branch_level = save_level;
}
Beispiel #8
0
static void remember_id(slice_index si, stip_structure_traversal *st)
{
  Goal const goal = SLICE_U(si).goal_handler.goal;
  if (goal.type==goal_kiss)
    id_to_be_kissed = GetPieceId(being_solved.spec[goal.target]);

  stip_traverse_structure_children(si,st);
}
Beispiel #9
0
static void detect_constrained_attack(slice_index si, stip_structure_traversal *st)
{
  if (st->context==stip_traversal_context_attack)
  {
    boolean * const result = st->param;
    *result = true;
  }
  else
    stip_traverse_structure_children(si,st);
}
Beispiel #10
0
static void substitute_enforce_annanised_walk(slice_index si,
                                              stip_structure_traversal *st)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  stip_traverse_structure_children(si,st);
  pipe_substitute(si,alloc_pipe(STAnnanEnforceObserverWalk));

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #11
0
/* Callback to stip_spin_off_testers
 * Spin a tester slice off a fork slice
 * @param si identifies the testing pipe slice
 * @param st address of structure representing traversal
 */
void stip_spin_off_testers_fork(slice_index si, stip_structure_traversal *st)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  SLICE_TESTER(si) = copy_slice(si);
  stip_traverse_structure_children(si,st);
  link_to_branch(SLICE_TESTER(si),SLICE_TESTER(SLICE_NEXT1(si)));
  SLICE_NEXT2(SLICE_TESTER(si)) = SLICE_TESTER(SLICE_NEXT2(si));

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

  stip_traverse_structure_children(si,st);

  {
    stip_deep_copies_type copies;
    stip_structure_traversal st_nested;

    slice_index const * const threat_start = st->param;
    slice_index const threat_start_tester = SLICE_TESTER(*threat_start);

    assert(*threat_start!=no_slice);
    assert(threat_start_tester!=no_slice);
    assert(SLICE_TYPE(threat_start_tester)==STThreatStart);

    {
      slice_index const prototype = alloc_pipe(STThreatDefeatedTester);
      attack_branch_insert_slices(threat_start_tester,&prototype,1);
    }

    init_deep_copy(&st_nested,st,&copies);
    stip_structure_traversal_override_single(&st_nested,
                                             STThreatDefeatedTester,
                                             &move_and_stop_copying);
    stip_structure_traversal_override_by_contextual(&st_nested,
                                                    slice_contextual_conditional_pipe,
                                                    &copy_shallow);
    stip_structure_traversal_override_by_contextual(&st_nested,
                                                    slice_contextual_testing_pipe,
                                                    &copy_shallow);
    stip_traverse_structure(threat_start_tester,&st_nested);

    SLICE_NEXT2(si) = copies[threat_start_tester];
  }

  {
    /* if the threats are short, max_unsolvable might interfere with enforcing
     * them */
    slice_index const prototype = alloc_reset_unsolvable_slice();
    attack_branch_insert_slices(SLICE_NEXT2(si),&prototype,1);
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #13
0
static void substitute_enforce_confronted_walk(slice_index si,
                                               stip_structure_traversal *st)
{
  slice_type const * const enforcer = st->param;

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

  stip_traverse_structure_children(si,st);
  pipe_substitute(si,alloc_pipe(*enforcer));

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #14
0
static void remember_counting(slice_index si, stip_structure_traversal *st)
{
  insertion_state_type * const state = st->param;

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

  state->are_we_counting_goal_reaching_moves = true;
  stip_traverse_structure_children(si,st);
  state->are_we_counting_goal_reaching_moves = false;

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #15
0
static void leave_exclusivity_testing(slice_index si,
                                      stip_structure_traversal *st)
{
  insertion_state_type * const state = st->param;

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

  state->are_we_testing_exclusivity = false;
  stip_traverse_structure_children(si,st);
  state->are_we_testing_exclusivity = true;

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

  stip_traverse_structure_children(si,st);

  {
    slice_index const prototype = alloc_pipe(STSuperguardsRemoveIllegalCaptures);
    slice_insertion_insert_contextually(si,st->context,&prototype,1);
  }

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

  stip_traverse_structure_children(si,st);

  {
    slice_index const prototype = alloc_pipe(STTakeAndMakeGenerateMake);
    slice_insertion_insert_contextually(si,st->context,&prototype,1);
  }

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

  stip_traverse_structure_children(si,st);

  {
    slice_index const prototype = alloc_pipe(STRepublicanKingPlacer);
    move_insert_slices(si,st->context,&prototype,1);
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #19
0
/* Determine whether there are more moves after this branch
 * @param si identifies root of subtree
 * @param st address of structure representing traversal
 */
static void remember_immobility(slice_index si, stip_structure_traversal *st)
{
  boolean * const goal_implies_immobility = st->param;

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

  stip_traverse_structure_children(si,st);

  if (SLICE_U(si).goal_filter.applies_to_who==goal_applies_to_starter)
    *goal_implies_immobility = true;

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
static void remember_goal_with_potential_king_capture(slice_index si,
                                                      stip_structure_traversal *st)
{
  insertion_state * const state = st->param;
  twin_id_type const save_own_king_capture_possible = state->own_king_capture_possible;

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

  state->own_king_capture_possible = twin_id;
  stip_traverse_structure_children(si,st);
  state->own_king_capture_possible = save_own_king_capture_possible;

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

  stip_traverse_structure_children(si,st);

  if (st->context==stip_traversal_context_defense)
  {
    slice_index const prototype = alloc_pipe(STRepublicanType1DeadEnd);
    defense_branch_insert_slices(si,&prototype,1);
  }

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

  if (st->context==stip_traversal_context_attack)
  {
    slice_index const prototype = alloc_testing_pipe(STThreatEnforcer);
    attack_branch_insert_slices(si,&prototype,1);
  }

  stip_traverse_structure_children(si,st);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #23
0
static void notify_medium(slice_index si, stip_structure_traversal *st)
{
  notification_struct * const notification = st->param;

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

  (*SLICE_U(si).twinning_event_handler.handler)(si,
                                                notification->event,
                                                notification->continued);

  stip_traverse_structure_children(si,st);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #24
0
static void substitute_avoid_promotion_moving(slice_index si,
        stip_structure_traversal *st)
{
    boolean const (* const enabled)[nr_sides] = st->param;

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

    stip_traverse_structure_children(si,st);

    if ((*enabled)[SLICE_STARTER(si)])
        pipe_substitute(si,alloc_pipe(STNoPromotionsRemovePromotionMoving));

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

  stip_traverse_structure_children(si,st);

  if (BGL_values[SLICE_STARTER(si)]!=BGL_infinity)
  {
    slice_index const prototype = alloc_pipe(STBGLEnforcer);
    slice_insertion_insert_contextually(si,st->context,&prototype,1);
  }

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

  if (is_constraint_irrelevant(SLICE_NEXT2(si)))
  {
    stip_traverse_structure_children_pipe(si,st);
    dealloc_slices(SLICE_NEXT2(si));
    pipe_remove(si);
  }
  else
    stip_traverse_structure_children(si,st);

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

  if (SLICE_STARTER(si)==Black)
  {
    slice_index const prototype = alloc_pipe(STBlackChecksNullMoveGenerator);
    slice_insertion_insert_contextually(si,st->context,&prototype,1);
  }

  stip_traverse_structure_children(si,st);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #28
0
static void insert_remover(slice_index si, stip_structure_traversal *st)
{
  boolean const (* const enabled)[nr_sides] = st->param;

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

  stip_traverse_structure_children(si,st);

  if ((*enabled)[SLICE_STARTER(si)])
  {
    slice_index const prototype = alloc_pipe(STNocaptureRemoveCaptures);
    slice_insertion_insert_contextually(si,st->context,&prototype,1);
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #29
0
static void write_defense(slice_index si, stip_structure_traversal *st)
{
  state_type * const state = st->param;
  stip_length_type const save_length = state->length;
  structure_traversal_level_type const save_level = state->branch_level;;

  state->branch_level = st->level;
  state->length = SLICE_U(si).branch.length;

  stip_traverse_structure_children(si,st);

  if (st->level==structure_traversal_level_top)
    state->nr_chars_written += fprintf(state->file,
                                                "%u",
                                                SLICE_U(si).branch.length/2+1);

  state->length = save_length;
  state->branch_level = save_level;
}
Beispiel #30
0
static void insert_counter_at_goal(slice_index si, stip_structure_traversal *st)
{
  insertion_struct * const insertion = st->param;

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

  stip_traverse_structure_children(si,st);

  if (st->context==stip_traversal_context_help && !insertion->inserted)
  {
    slice_index const prototype = alloc_maxsolutions_counter_slice(insertion->incomplete);
    help_branch_insert_slices_behind_proxy(SLICE_NEXT2(si),&prototype,1,si);
    insertion->inserted = true;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}