static slice_index make_opponent_moves_counter_fork(Side side) { slice_index result; TraceFunctionEntry(__func__); TraceEnumerator(Side,side); TraceFunctionParamListEnd(); if (is_countnropponentmoves_defense_move_optimisation_enabled(side)) { slice_index const proxy = alloc_proxy_slice(); slice_index const prototypes[] = { alloc_opponent_moves_counter_slice(), alloc_legal_attack_counter_slice() }; enum { nr_prototypes = sizeof prototypes / sizeof prototypes[0] }; slice_index const attack = alloc_defense_branch(slack_length+2,slack_length+1); slice_insertion_insert(attack,prototypes,nr_prototypes); link_to_branch(proxy,attack); result = alloc_conditional_pipe(STOpponentMovesCounterFork,proxy); solving_impose_starter(result,side); } else result = alloc_proxy_slice(); TraceFunctionExit(__func__); TraceFunctionResult("%u",result); TraceFunctionResultEnd(); return result; }
static slice_index make_cagecirce_noncapture_finder(Side side) { slice_index result; if (circe_variant.determine_rebirth_square==circe_determine_rebirth_square_cage || anticirce_variant.determine_rebirth_square==circe_determine_rebirth_square_cage) { slice_index const proxy_branch = alloc_proxy_slice(); slice_index const help = alloc_help_branch(slack_length+1,slack_length+1); slice_index const proxy_goal = alloc_proxy_slice(); slice_index const system = alloc_goal_capture_reached_tester_system(); link_to_branch(proxy_goal,system); { slice_index const tester = branch_find_slice(STGoalReachedTester, proxy_goal, stip_traversal_context_intro); assert(tester!=no_slice); pipe_append(SLICE_NEXT2(tester),alloc_not_slice()); SLICE_U(tester).goal_handler.goal.type = goal_negated; help_branch_set_end_goal(help,proxy_goal,1); link_to_branch(proxy_branch,help); result = alloc_conditional_pipe(STCageCirceNonCapturingMoveFinder,proxy_branch); solving_impose_starter(result,side); } } else result = alloc_proxy_slice(); return result; }
static slice_index make_suffocation_by_paralysis_detector(Side side) { slice_index const proxy = alloc_proxy_slice(); slice_index const result = alloc_conditional_pipe(STPiecesParalysingSuffocationFinderFork,proxy); slice_index const attack = alloc_battle_branch(slack_length+1,slack_length+1); slice_index const prototype = alloc_pipe(STPiecesParalysingSuffocationFinder); slice_insertion_insert(attack,&prototype,1); link_to_branch(proxy,attack); solving_impose_starter(result,side); return result; }
static slice_index make_move_generator(Side side) { slice_index const proxy = alloc_proxy_slice(); slice_index const result = alloc_conditional_pipe(STMoveGeneratorFork,proxy); slice_index const generating = alloc_pipe(STGeneratingMovesForPiece); slice_index const ortho = alloc_pipe(STMovesForPieceBasedOnWalkGenerator); slice_index const generated = create_slice(STGeneratedMovesForPiece); pipe_append(proxy,generating); pipe_append(generating,ortho); pipe_link(ortho,generated); solving_impose_starter(result,side); return result; }
static void make_is_square_observed(Side side) { slice_index const proxy = alloc_proxy_slice(); slice_index const testing = alloc_pipe(STTestingIfSquareIsObserved); slice_index const determine_walk = alloc_pipe(STDetermineObserverWalk); slice_index const testing_specific = alloc_pipe(STTestingIfSquareIsObservedWithSpecificWalk); slice_index const optimising = alloc_pipe(STOptimisingObserverWalk); slice_index const track_back = alloc_pipe(STTrackBackFromTargetAccordingToObserverWalk); temporary_hack_is_square_observed[side] = alloc_conditional_pipe(STIsSquareObservedFork,proxy); temporary_hack_is_square_observed_specific[side] = alloc_conditional_pipe(STIsSquareObservedFork,testing_specific); pipe_link(proxy,testing); pipe_link(testing,determine_walk); pipe_link(determine_walk,testing_specific); pipe_link(testing_specific,optimising); pipe_link(optimising,track_back); pipe_link(track_back,alloc_false_slice()); solving_impose_starter(temporary_hack_is_square_observed[side],side); solving_impose_starter(temporary_hack_is_square_observed_specific[side],side); }
static slice_index make_ultra_mummer_length_measurer(Side side) { slice_index result; slice_index const proxy_branch = alloc_proxy_slice(); slice_index const help = alloc_help_branch(slack_length+1,slack_length+1); slice_index const proxy_goal = alloc_proxy_slice(); slice_index const system = alloc_goal_any_reached_tester_system(); link_to_branch(proxy_goal,system); help_branch_set_end_goal(help,proxy_goal,1); link_to_branch(proxy_branch,help); result = alloc_conditional_pipe(STUltraMummerMeasurerFork,proxy_branch); solving_impose_starter(result,side); return result; }
static slice_index make_observation_geometry_validator(Side side) { slice_index const proxy = alloc_proxy_slice(); slice_index const result = alloc_conditional_pipe(STValidatingObservationGeometryFork,proxy); slice_index const enforce_walk = alloc_pipe(STEnforceObserverWalk); slice_index const testing = alloc_pipe(STValidatingObservationGeometry); pipe_link(proxy,testing); pipe_link(testing,enforce_walk); pipe_link(enforce_walk,alloc_true_slice()); solving_impose_starter(result,side); return result; }
static slice_index make_back_home_finder(Side side) { slice_index const proxy = alloc_proxy_slice(); slice_index const result = alloc_conditional_pipe(STBackHomeFinderFork,proxy); slice_index const defense = alloc_defense_branch(slack_length+1,slack_length+1); slice_index const prototypes[] = { alloc_pipe(STBackHomeMovesOnly), alloc_legal_defense_counter_slice() }; slice_insertion_insert(defense,prototypes,2); link_to_branch(proxy,defense); solving_impose_starter(result,side); return result; }
static slice_index make_castling_intermediate_move_legality_tester(Side side) { slice_index result; slice_index const proxy_branch = alloc_proxy_slice(); slice_index const help = alloc_help_branch(slack_length+1,slack_length+1); slice_index const proxy_goal = alloc_proxy_slice(); slice_index const system = alloc_goal_any_reached_tester_system(); link_to_branch(proxy_goal,system); help_branch_set_end_goal(help,proxy_goal,1); link_to_branch(proxy_branch,help); result = alloc_conditional_pipe(STCastlingIntermediateMoveLegalityTester,proxy_branch); solving_impose_starter(result,side); return result; }
static slice_index make_circe_take_make_rebirth_squares_finder(Side side) { slice_index result; slice_index const proxy_branch = alloc_proxy_slice(); slice_index const help = alloc_help_branch(slack_length+1,slack_length+1); slice_index const prototype = alloc_pipe(STTakeMakeCirceCollectRebirthSquares); slice_index const executing = alloc_pipe(STExecutingKingCapture); link_to_branch(proxy_branch,help); help_branch_insert_slices(help,&prototype,1); slice_insertion_insert(help,&executing,1); result = alloc_conditional_pipe(STTakeMakeCirceCollectRebirthSquaresFork,proxy_branch); solving_impose_starter(result,side); return result; }
static slice_index make_check_tester(void) { slice_index const proxy = alloc_proxy_slice(); slice_index const result = alloc_conditional_pipe(STCheckTesterFork,proxy); slice_index const testing = alloc_pipe(STTestingCheck); slice_index const initialiser = alloc_pipe(STKingSquareObservationTesterPlyInitialiser); slice_index const king_square_observation_tester = alloc_pipe(STKingSquareObservationTester); slice_index const tested = create_slice(STTestedCheck); link_to_branch(proxy,testing); pipe_append(testing,initialiser); pipe_append(initialiser,king_square_observation_tester); pipe_link(king_square_observation_tester,tested); solving_impose_starter(result,Black); return result; }
/* 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; }
/* 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; }
static slice_index make_brunner_check_defense_finder(Side side) { slice_index result; slice_index const proxy_branch = alloc_proxy_slice(); slice_index const help = alloc_help_branch(slack_length+1,slack_length+1); slice_index const proxy_goal = alloc_proxy_slice(); slice_index const system = alloc_goal_any_reached_tester_system(); slice_index const executing = alloc_pipe(STExecutingKingCapture); link_to_branch(proxy_goal,system); help_branch_set_end_goal(help,proxy_goal,1); slice_insertion_insert(help,&executing,1); link_to_branch(proxy_branch,help); result = alloc_conditional_pipe(STBrunnerDefenderFinder,proxy_branch); solving_impose_starter(result,side); return result; }
static slice_index make_exclusive_mating_move_counter_fork(Side side) { slice_index result; slice_index const proxy_branch = alloc_proxy_slice(); slice_index const proxy_to_goal = alloc_proxy_slice(); Goal const goal = { goal_mate, initsquare }; slice_index const tester_system = alloc_goal_mate_reached_tester_system(); slice_index const tester_slice = alloc_goal_reached_tester_slice(goal,tester_system); slice_index const attack = alloc_battle_branch(slack_length+1,slack_length+1); slice_index const counter = alloc_pipe(STExclusiveChessGoalReachingMoveCounter); link_to_branch(counter,tester_slice); link_to_branch(proxy_to_goal,counter); link_to_branch(proxy_branch,attack); battle_branch_insert_direct_end_of_branch_goal(attack,proxy_to_goal); result = alloc_conditional_pipe(STExclusiveChessMatingMoveCounterFork,proxy_branch); solving_impose_starter(result,side); return result; }
static slice_index make_check_validator(Side side) { slice_index const proxy = alloc_proxy_slice(); slice_index const result = alloc_conditional_pipe(STValidatingCheckFork,proxy); slice_index const check = alloc_pipe(STValidatingCheck); slice_index const enforce_walk = alloc_pipe(STEnforceObserverWalk); slice_index const observer = alloc_pipe(STValidatingObserver); slice_index const geometry = alloc_pipe(STValidatingObservationGeometry); pipe_link(proxy,check); pipe_link(check,enforce_walk); pipe_link(enforce_walk,observer); pipe_link(observer,geometry); pipe_link(geometry,alloc_true_slice()); solving_impose_starter(result,side); return result; }
/* Allocate a STGoalImmobileReachedTester slice. * @param starter_or_adversary is the starter immobilised or its adversary? * @return index of allocated slice */ slice_index alloc_goal_immobile_reached_tester_slice(goal_applies_to_starter_or_adversary starter_or_adversary) { slice_index result; TraceFunctionEntry(__func__); TraceValue("%u",starter_or_adversary); TraceFunctionParamListEnd(); { slice_index const proxy = alloc_proxy_slice(); slice_index const tester = alloc_pipe(STImmobilityTester); result = alloc_conditional_pipe(STGoalImmobileReachedTester,proxy); pipe_link(proxy,tester); link_to_branch(tester,alloc_defense_branch(1,1)); SLICE_U(result).goal_filter.applies_to_who = starter_or_adversary; } TraceFunctionExit(__func__); TraceFunctionResult("%u",result); TraceFunctionResultEnd(); return result; }
void insert_temporary_hacks(slice_index root_slice) { TraceFunctionEntry(__func__); TraceFunctionParam("%u",root_slice); TraceFunctionParamListEnd(); { slice_index const proxy = alloc_proxy_slice(); slice_index const entry_point = alloc_conditional_pipe(STTemporaryHackFork,proxy); slice_index const inverter = alloc_move_inverter_slice(); pipe_link(proxy,alloc_true_slice()); temporary_hack_mate_tester[Black] = make_mate_tester_fork(Black); temporary_hack_mate_tester[White] = make_mate_tester_fork(White); temporary_hack_exclusive_mating_move_counter[Black] = make_exclusive_mating_move_counter_fork(Black); temporary_hack_exclusive_mating_move_counter[White] = make_exclusive_mating_move_counter_fork(White); temporary_hack_brunner_check_defense_finder[Black] = make_brunner_check_defense_finder(Black); temporary_hack_brunner_check_defense_finder[White] = make_brunner_check_defense_finder(White); temporary_hack_ultra_mummer_length_measurer[Black] = make_ultra_mummer_length_measurer(Black); temporary_hack_ultra_mummer_length_measurer[White] = make_ultra_mummer_length_measurer(White); temporary_hack_move_legality_tester[Black] = make_move_legality_tester(Black); temporary_hack_move_legality_tester[White] = make_move_legality_tester(White); temporary_hack_king_capture_legality_tester[Black] = make_king_capture_legality_tester(Black); temporary_hack_king_capture_legality_tester[White] = make_king_capture_legality_tester(White); temporary_hack_cagecirce_noncapture_finder[Black] = make_cagecirce_noncapture_finder(Black); temporary_hack_cagecirce_noncapture_finder[White] = make_cagecirce_noncapture_finder(White); temporary_hack_circe_take_make_rebirth_squares_finder[Black] = make_circe_take_make_rebirth_squares_finder(Black); temporary_hack_circe_take_make_rebirth_squares_finder[White] = make_circe_take_make_rebirth_squares_finder(White); temporary_hack_castling_intermediate_move_legality_tester[Black] = make_castling_intermediate_move_legality_tester(Black); temporary_hack_castling_intermediate_move_legality_tester[White] = make_castling_intermediate_move_legality_tester(White); temporary_hack_opponent_moves_counter[Black] = make_opponent_moves_counter_fork(Black); temporary_hack_opponent_moves_counter[White] = make_opponent_moves_counter_fork(White); temporary_hack_back_home_finder[Black] = make_back_home_finder(Black); temporary_hack_back_home_finder[White] = make_back_home_finder(White); temporary_hack_suffocation_by_paralysis_finder[Black] = make_suffocation_by_paralysis_detector(Black); temporary_hack_suffocation_by_paralysis_finder[White] = make_suffocation_by_paralysis_detector(White); temporary_hack_move_generator[Black] = make_move_generator(Black); temporary_hack_move_generator[White] = make_move_generator(White); make_is_square_observed(Black); make_is_square_observed(White); temporary_hack_check_validator[Black] = make_check_validator(Black); temporary_hack_check_validator[White] = make_check_validator(White); temporary_hack_observation_validator[Black] = make_observation_validator(Black); temporary_hack_observation_validator[White] = make_observation_validator(White); temporary_hack_observer_validator[Black] = make_observer_validator(Black); temporary_hack_observer_validator[White] = make_observer_validator(White); temporary_hack_observation_geometry_validator[Black] = make_observation_geometry_validator(Black); temporary_hack_observation_geometry_validator[White] = make_observation_geometry_validator(White); temporary_hack_check_tester = make_check_tester(); slice_insertion_insert(root_slice,&entry_point,1); pipe_append(proxy,temporary_hack_mate_tester[White]); pipe_append(temporary_hack_mate_tester[White], temporary_hack_exclusive_mating_move_counter[White]); pipe_append(temporary_hack_exclusive_mating_move_counter[White], temporary_hack_brunner_check_defense_finder[White]); pipe_append(temporary_hack_brunner_check_defense_finder[White], temporary_hack_ultra_mummer_length_measurer[White]); pipe_append(temporary_hack_ultra_mummer_length_measurer[White], temporary_hack_move_legality_tester[White]); pipe_append(temporary_hack_move_legality_tester[White], temporary_hack_king_capture_legality_tester[White]); pipe_append(temporary_hack_king_capture_legality_tester[White], temporary_hack_cagecirce_noncapture_finder[White]); pipe_append(temporary_hack_cagecirce_noncapture_finder[White], temporary_hack_circe_take_make_rebirth_squares_finder[White]); pipe_append(temporary_hack_circe_take_make_rebirth_squares_finder[White], temporary_hack_castling_intermediate_move_legality_tester[White]); pipe_append(temporary_hack_castling_intermediate_move_legality_tester[White], temporary_hack_opponent_moves_counter[White]); pipe_append(temporary_hack_opponent_moves_counter[White], temporary_hack_back_home_finder[White]); pipe_append(temporary_hack_back_home_finder[White], temporary_hack_suffocation_by_paralysis_finder[White]); pipe_append(temporary_hack_suffocation_by_paralysis_finder[White], temporary_hack_move_generator[White]); pipe_append(temporary_hack_move_generator[White], temporary_hack_is_square_observed_specific[White]); pipe_append(temporary_hack_is_square_observed_specific[White], temporary_hack_is_square_observed[White]); pipe_append(temporary_hack_is_square_observed[White], temporary_hack_check_validator[White]); pipe_append(temporary_hack_check_validator[White], temporary_hack_observation_validator[White]); pipe_append(temporary_hack_observation_validator[White], temporary_hack_observation_geometry_validator[White]); pipe_append(temporary_hack_observation_geometry_validator[White], temporary_hack_observer_validator[White]); pipe_append(temporary_hack_observer_validator[White], inverter); pipe_append(inverter,temporary_hack_mate_tester[Black]); pipe_append(temporary_hack_mate_tester[Black], temporary_hack_exclusive_mating_move_counter[Black]); pipe_append(temporary_hack_exclusive_mating_move_counter[Black], temporary_hack_brunner_check_defense_finder[Black]); pipe_append(temporary_hack_brunner_check_defense_finder[Black], temporary_hack_ultra_mummer_length_measurer[Black]); pipe_append(temporary_hack_ultra_mummer_length_measurer[Black], temporary_hack_move_legality_tester[Black]); pipe_append(temporary_hack_move_legality_tester[Black], temporary_hack_king_capture_legality_tester[Black]); pipe_append(temporary_hack_king_capture_legality_tester[Black], temporary_hack_cagecirce_noncapture_finder[Black]); pipe_append(temporary_hack_cagecirce_noncapture_finder[Black], temporary_hack_circe_take_make_rebirth_squares_finder[Black]); pipe_append(temporary_hack_circe_take_make_rebirth_squares_finder[Black], temporary_hack_castling_intermediate_move_legality_tester[Black]); pipe_append(temporary_hack_castling_intermediate_move_legality_tester[Black], temporary_hack_opponent_moves_counter[Black]); pipe_append(temporary_hack_opponent_moves_counter[Black], temporary_hack_back_home_finder[Black]); pipe_append(temporary_hack_back_home_finder[Black], temporary_hack_suffocation_by_paralysis_finder[Black]); pipe_append(temporary_hack_suffocation_by_paralysis_finder[Black], temporary_hack_move_generator[Black]); pipe_append(temporary_hack_move_generator[Black], temporary_hack_is_square_observed_specific[Black]); pipe_append(temporary_hack_is_square_observed_specific[Black], temporary_hack_is_square_observed[Black]); pipe_append(temporary_hack_is_square_observed[Black], temporary_hack_check_validator[Black]); pipe_append(temporary_hack_check_validator[Black], temporary_hack_observation_validator[Black]); pipe_append(temporary_hack_observation_validator[Black], temporary_hack_observation_geometry_validator[Black]); pipe_append(temporary_hack_observation_geometry_validator[Black], temporary_hack_observer_validator[Black]); pipe_append(temporary_hack_observer_validator[Black], temporary_hack_check_tester); if (SLICE_STARTER(root_slice)==Black) pipe_append(proxy,alloc_move_inverter_slice()); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }