Example #1
0
/* Allocate a STKillerAttackCollector slice.
 * @return index of allocated slice
 */
slice_index alloc_killer_attack_collector_slice(void)
{
  slice_index result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  result = alloc_pipe(STKillerAttackCollector);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #2
0
/* Allocate a STMaxSolutionsGuard slice.
 * @return allocated slice
 */
slice_index alloc_maxsolutions_guard_slice(void)
{
  slice_index result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  result = alloc_pipe(STMaxSolutionsGuard);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #3
0
/* Allocate a STFindDefense slice.
 * @return index of allocated slice
 */
slice_index alloc_find_defense_slice(void)
{
  slice_index result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  result = alloc_pipe(STFindDefense);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #4
0
/* Parse a stipulation branch
 * @param tok input token
 * @param start index of entry into solving machinery
 * @param proxy index of branch; no_slice if branch couldn't be
 *              parsed
 * @param level nesting level of the operand (0 means top level)
 * @return remainder of input token; 0 if parsing failed
 */
static char *ParseStructuredStip_branch(char *tok,
                                        slice_index start,
                                        slice_index proxy,
                                        expression_type *type,
                                        unsigned int level)
{
  stip_length_type min_length = 0;
  stip_length_type max_length = 0;

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%s",tok);
  TraceFunctionParam("%u",start);
  TraceFunctionParam("%u",proxy);
  TraceFunctionParam("%u",level);
  TraceFunctionParamListEnd();

  tok = ParseStructuredStip_branch_length(tok,&min_length,&max_length);

  switch (tolower(tok[0]))
  {
    case 'd':
      *type = expression_type_defense;
      tok = ParseStructuredStip_branch_d(tok+1,min_length,max_length,start,proxy,level);
      break;

    case 's':
      *type = expression_type_attack;
      tok = ParseStructuredStip_branch_s(tok+1,min_length,max_length,start,proxy,level);
      break;

    case 'a':
      *type = expression_type_attack;
      tok = ParseStructuredStip_branch_a(tok+1,min_length,max_length,start,proxy,level);
      break;

    case 'h':
      *type = expression_type_attack;
      tok = ParseStructuredStip_branch_h(tok+1,min_length,max_length,start,proxy,level);
      break;

    default:
      break;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResult("%s",tok);
  TraceFunctionResultEnd();
  return tok;
}
Example #5
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;
}
Example #6
0
/* Allocate a system of slices that tests whether the side to be immobilised has
 * been
 * @return index of entry slice
 */
slice_index alloc_goal_immobile_reached_tester_system(void)
{
  slice_index result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  result = alloc_goal_immobile_reached_tester_slice(goal_applies_to_starter);
  pipe_link(result,alloc_true_slice());

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #7
0
/* Allocate a STStopOnShortSolutionsFilter slice.
 * @param length full length
 * @param length minimum length
 * @return allocated slice
 */
slice_index alloc_stoponshortsolutions_filter(stip_length_type length,
                                              stip_length_type min_length)
{
  slice_index result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  result = alloc_branch(STStopOnShortSolutionsFilter,length,min_length);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #8
0
/* Allocate a STGoalConstraintTester slice
 * @param proxy_to_constraint prototype of slice that must not be solvable
 * @return index of allocated slice
 */
slice_index alloc_goal_constraint_tester_slice(slice_index proxy_to_constraint)
{
  slice_index result;

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

  result = alloc_conditional_pipe(STGoalConstraintTester,proxy_to_constraint);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #9
0
/* Allocate a STGoalCheckReachedTester slice.
 * @param starter_or_adversary is the starter or its adversary to be in check?
 * @return index of allocated slice
 */
slice_index alloc_goal_check_reached_tester_slice(goal_applies_to_starter_or_adversary starter_or_adversary)
{
  slice_index result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  result = alloc_pipe(STGoalCheckReachedTester);
  SLICE_U(result).goal_filter.applies_to_who = starter_or_adversary;

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #10
0
/* Delegate validating to next2
 * @param si identifies the fork
 * @return true iff the observation is valid
 */
boolean fork_validate_observation_recursive_delegate(slice_index si)
{
  boolean result;

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

  result =  validate_observation_recursive(SLICE_NEXT2(si));

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #11
0
/* Allocate a STNullMovePlayer slice.
 * @param after_move identifies landing slice after move playing
 * @return index of allocated slice
 */
static slice_index alloc_null_move_player_slice(slice_index after_move)
{
  slice_index result;

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

  result = alloc_fork_slice(STNullMovePlayer,after_move);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #12
0
/* Allocate a STDoubleMateFilter slice.
 * @return index of allocated slice
 */
slice_index alloc_doublemate_filter_slice(void)
{
  slice_index result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  result = alloc_conditional_pipe(STDoubleMateFilter,
                                  alloc_goal_immobile_reached_tester_system());

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #13
0
/* Allocate a STConstraintSolver slice
 * @param proxy_to_constraint prototype of slice that must not be solvable
 * @return index of allocated slice
 */
slice_index alloc_constraint_solver_slice(slice_index proxy_to_constraint)
{
  slice_index result;

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

  result = alloc_fork_slice(STConstraintSolver,proxy_to_constraint);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #14
0
/* Delegate testing observation to next2
 * @param si identifies the fork
 * @return true iff the target square is observed
 */
boolean fork_is_square_observed_nested_delegate(slice_index si,
                                                validator_id evaluate)
{
  boolean result;

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

  result = is_square_observed_nested(SLICE_NEXT2(si),evaluate);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #15
0
/* Allocate a STMaxThreatLength slice
 */
static slice_index alloc_maxthreatlength_guard(slice_index threat_start)
{
  slice_index result;

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

  result = alloc_testing_pipe(STMaxThreatLength);
  SLICE_NEXT2(result) = threat_start;

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #16
0
/* Produce the sequence of slices that tests whether a self stipulation has been
 * solved
 * @param proxy_to_goal identifies sequence of slices testing for the goal
 * @return identifier of the entry slice
 */
static slice_index MakeEndOfSelfPlay(slice_index proxy_to_goal)
{
    slice_index result;

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

    result = alloc_defense_branch(1,1);
    battle_branch_insert_self_end_of_branch_goal(result,proxy_to_goal);

    TraceFunctionExit(__func__);
    TraceFunctionResult("%u",result);
    TraceFunctionResultEnd();
    return result;
}
Example #17
0
static slice_index MakeReflexBranch(slice_index proxy_to_semi)
{
    slice_index result;

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

    result = stip_deep_copy(proxy_to_semi);
    pipe_append(result,alloc_not_slice());

    TraceFunctionExit(__func__);
    TraceFunctionResult("%u",result);
    TraceFunctionResultEnd();
    return result;
}
Example #18
0
/* Make sure that the observer has the expected walk - confronted or originally
 * @return true iff the observation is valid
 */
boolean facetoface_enforce_observer_walk(slice_index si)
{
  numvec const dir_confronter = trait[nbply]==White ? dir_up : dir_down;
  boolean result;

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

  result = enforce_possibly_confronted_observer_walk(si,dir_confronter);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #19
0
/* Determine the length of a move in the presence of forced squares; the higher
 * the value the more likely the move is going to be played.
 * @return a value expressing the precedence of this move
 */
int forced_squares_measure_length(void)
{
  square const sq_arrival = move_generation_stack[CURRMOVE_OF_PLY(nbply)].arrival;
  SquareFlags const flag = trait[nbply]==White ? WhForcedSq : BlForcedSq;
  int const result = TSTFLAG(sq_spec[sq_arrival],flag);

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  TraceValue("%x\n",sq_spec[sq_arrival]);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #20
0
static numecoup find_killer_move(void)
{
  numecoup result;

  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  for (result = CURRMOVE_OF_PLY(nbply); result>MOVEBASE_OF_PLY(nbply); --result)
    if (is_killer_move(result))
      break;

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #21
0
static boolean is_killer_move(numecoup i)
{
  boolean result;

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

  result = killer_moves[nbply].departure==move_generation_stack[i].departure
           && killer_moves[nbply].arrival==move_generation_stack[i].arrival;

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #22
0
/* Allocate a STKeepMatingFilter slice
 * @param mating mating side
 * @return identifier of allocated slice
 */
static slice_index alloc_keepmating_filter_slice(Side mating)
{
  slice_index result;

  TraceFunctionEntry(__func__);
  TraceEnumerator(Side,mating);
  TraceFunctionParamListEnd();

  result = alloc_pipe(STKeepMatingFilter);
  SLICE_U(result).keepmating_guard.mating = mating;

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #23
0
/* Try the current rebirth square
 * @return true iff there are more rebirth squares to be tried (or the same
 *              again)
 */
static boolean try_rebirth_square(slice_index si)
{
  boolean result;

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

  post_move_iteration_solve_fork(si);
  result = post_move_iteration_is_locked();

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #24
0
/* Delegate testing to next2
 * @param si identifies the check tester
 * @param side_in_check which side?
 * @return true iff side_in_check is in check according to slice si
 */
boolean fork_is_in_check_recursive_delegate(slice_index si, Side side_in_check)
{
  boolean result;

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

  result = is_in_check_recursive(SLICE_NEXT2(si),side_in_check);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #25
0
/* Make sure that the observer has the expected walk - confronted or originally
 * @return true iff the observation is valid
 */
boolean cheektocheek_enforce_observer_walk(slice_index si)
{
  boolean result;

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

  result = (enforce_possibly_confronted_observer_walk(si,dir_left)
            || enforce_possibly_confronted_observer_walk(si,dir_right));

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #26
0
/* Validate an observation according to Central Chess
 * @return true iff the observation is valid
 */
boolean central_validate_observation(slice_index si)
{
  boolean result;

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

  result = (is_mover_supported(CURRMOVE_OF_PLY(nbply))
            && pipe_validate_observation_recursive_delegate(si));

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #27
0
/* Allocate an STOutputModeSelector slice
 * @param mode output mode to be selected by the allocated slice
 * @return identifier of the allocated slice
 */
slice_index alloc_output_mode_selector(output_mode mode)
{
  slice_index result;

  TraceFunctionEntry(__func__);
  TraceEnumerator(output_mode,mode);
  TraceFunctionParamListEnd();

  result = alloc_pipe(STOutputModeSelector);
  SLICE_U(result).output_mode_selector.mode = mode;

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #28
0
/* Validate an observation according to Shielded Kings
 * @return true iff the observation is valid
 */
boolean shielded_kings_validate_observation(slice_index si)
{
    boolean result;

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

    result = (is_not_king_captures_guarded_king(CURRMOVE_OF_PLY(nbply))
              && pipe_validate_observation_recursive_delegate(si));

    TraceFunctionExit(__func__);
    TraceFunctionResult("%u",result);
    TraceFunctionResultEnd();
    return result;
}
Example #29
0
/* Validate an observation according to Superguards
 * @return true iff the observation is valid
 */
boolean superguards_validate_observation(slice_index si)
{
  boolean result;

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

  result = (is_target_unguarded(CURRMOVE_OF_PLY(nbply))
            && pipe_validate_observation_recursive_delegate(si));

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
Example #30
0
/* Parse a help branch
 * @param tok input token
 * @param min_length minimal number of half moves
 * @param max_length maximal number of half moves
 * @param start index of entry into solving machinery
 * @param proxy index of branch; no_slice if branch couldn't be
 *              parsed
 * @param level nesting level of the operand (0 means top level)
 * @return remainder of input token; 0 if parsing failed
 */
static char *ParseStructuredStip_branch_h(char *tok,
                                          stip_length_type min_length,
                                          stip_length_type max_length,
                                          slice_index start,
                                          slice_index proxy,
                                          unsigned int level)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%s",tok);
  TraceFunctionParam("%u",min_length);
  TraceFunctionParam("%u",max_length);
  TraceFunctionParam("%u",start);
  TraceFunctionParam("%u",proxy);
  TraceFunctionParam("%u",level);
  TraceFunctionParamListEnd();

  {
    boolean parry = false;
    slice_index const branch = ParseStructuredStip_make_branch_h(min_length,
                                                                 max_length);
    link_to_branch(proxy,branch);

    tok = ParseStructuredStip_branch_h_operand(tok,start,proxy,max_length,level);

    if (tok!=0 && token_starts_with("?+?",tok))
    {
      tok += 3;
      parry = true;
    }

    if (tok!=0 && tok[0]=='h')
    {
      tok = ParseStructuredStip_branch_h_operand(tok+1,start,proxy,max_length+1,level);
      if (parry)
        help_branch_insert_check_zigzag(proxy);
      if (level==0)
        select_output_mode(proxy,output_mode_line);
    }
    else
      tok = 0;
  }

  TraceFunctionExit(__func__);
  TraceFunctionResult("%s",tok);
  TraceFunctionResultEnd();
  return tok;
}