void intelligent_place_white_rider(unsigned int placed_index, square placed_on, void (*go_on)(void)) { piece_walk_type const placed_type = white[placed_index].type; Flags const placed_flags = white[placed_index].flags; square const placed_comes_from = white[placed_index].diagram_square; int const dir = GuardDir[placed_type-Pawn][placed_on].dir; square const target = GuardDir[placed_type-Pawn][placed_on].target; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); switch (dir) { case guard_dir_check_uninterceptable: break; case guard_dir_guard_uninterceptable: if (placed_index>index_of_guarding_piece && intelligent_reserve_officer_moves_from_to(White, placed_comes_from, placed_type, placed_on)) { occupy_square(placed_on,placed_type,placed_flags); (*go_on)(); intelligent_unreserve(); } break; default: if (intelligent_reserve_officer_moves_from_to(White, placed_comes_from, placed_type, placed_on)) { occupy_square(placed_on,placed_type,placed_flags); if (placed_index>index_of_guarding_piece || dir==0 || TSTFLAG(being_solved.spec[target],Black) || !is_line_empty(placed_on,target,dir)) (*go_on)(); else intelligent_intercept_guard_by_white(target,dir,go_on); intelligent_unreserve(); } break; } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_pinned_unpromoted_black_pawn(unsigned int placed_index, square placed_on, void (*go_on)(void)) { Flags const placed_flags = black[placed_index].flags; square const placed_comes_from = black[placed_index].diagram_square; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); if (!TSTFLAGMASK(sq_spec[placed_on],BIT(BlBaseSq)|BIT(BlPromSq)) && !black_pawn_attacks_king(placed_on) && intelligent_reserve_black_pawn_moves_from_to_no_promotion(placed_comes_from, placed_on)) { occupy_square(placed_on,Pawn,placed_flags); (*go_on)(); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_pinned_promoted_black_knight(unsigned int placed_index, square placed_on, void (*go_on)(void)) { square const placed_comes_from = black[placed_index].diagram_square; Flags const placed_flags = black[placed_index].flags; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); if ((being_solved.king_square[White]==initsquare || CheckDir[Knight][being_solved.king_square[White]-placed_on]==0) && intelligent_reserve_promoting_black_pawn_moves_from_to(placed_comes_from, Knight, placed_on)) { occupy_square(placed_on,Knight,placed_flags); (*go_on)(); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_promoted_black_rider(unsigned int placed_index, piece_walk_type promotee_type, square placed_on, void (*go_on)(void)) { square const placed_comes_from = black[placed_index].diagram_square; int const check_diff = being_solved.king_square[White]-placed_on; int const check_dir = CheckDir[promotee_type][check_diff]; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceWalk(promotee_type); TraceSquare(placed_on); TraceFunctionParamListEnd(); if (check_dir!=check_diff && intelligent_reserve_promoting_black_pawn_moves_from_to(placed_comes_from, promotee_type, placed_on)) { place_rider(placed_index,promotee_type,placed_on,go_on); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
/* Place the white king; intercept checks if necessary * @param place_on where to place the king * @param go_on what to do after having placed the king? */ void intelligent_place_white_king(square place_on, void (*go_on)(void)) { TraceFunctionEntry(__func__); TraceSquare(place_on); TraceFunctionParamListEnd(); if (!guards_from(place_on) && !is_square_uninterceptably_observed_ortho(Black,place_on) && intelligent_reserve_white_king_moves_from_to(white[index_of_king].diagram_square, place_on)) { being_solved.king_square[White] = place_on; occupy_square(place_on,King,white[index_of_king].flags); current_direction = vec_queen_start-1; go_on_after = go_on; continue_intercepting_checks(); being_solved.king_square[White] = initsquare; empty_square(place_on); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_black_rider(unsigned int placed_index, square placed_on, void (*go_on)(void)) { piece_walk_type const intercepter_type = black[placed_index].type; square const placed_comes_from = black[placed_index].diagram_square; int const check_diff = being_solved.king_square[White]-placed_on; int const check_dir = CheckDir[intercepter_type][check_diff]; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); if (check_dir!=check_diff && intelligent_reserve_officer_moves_from_to(Black, placed_comes_from, intercepter_type, placed_on)) { place_rider(placed_index,intercepter_type,placed_on,go_on); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
static void by_knight(slice_index si, unsigned int index_of_checker, square const check_from) { int const diff = being_solved.king_square[Black]-check_from; int const dir = CheckDir[Knight][diff]; TraceFunctionEntry(__func__); TraceFunctionParam("%u",index_of_checker); TraceSquare(check_from); TraceFunctionParamListEnd(); if (dir!=0 && intelligent_reserve_white_officer_moves_from_to_checking(white[index_of_checker].diagram_square, Knight, check_from)) { occupy_square(check_from,Knight,white[index_of_checker].flags); init_disturb_mate_dir(check_from,being_solved.king_square[Black]-check_from); pipe_solve_delegate(si); fini_disturb_mate_dir(); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
static void by_rider(slice_index si, unsigned int index_of_checker, square const check_from) { piece_walk_type const checker_type = white[index_of_checker].type; Flags const checker_flags = white[index_of_checker].flags; int const diff = being_solved.king_square[Black]-check_from; int const dir = CheckDir[checker_type][diff]; TraceFunctionEntry(__func__); TraceFunctionParam("%u",index_of_checker); TraceSquare(check_from); TraceFunctionParamListEnd(); if (dir!=0 && intelligent_reserve_white_officer_moves_from_to_checking(white[index_of_checker].diagram_square, checker_type, check_from)) { occupy_square(check_from,checker_type,checker_flags); remember_mating_line(checker_type,check_from,+1); pipe_solve_delegate(si); remember_mating_line(checker_type,check_from,-1); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
static void by_unpromoted_pawn(slice_index si, unsigned int index_of_checker, square const check_from) { square const checker_from = white[index_of_checker].diagram_square; Flags const checker_flags = white[index_of_checker].flags; SquareFlags const prom_square = BIT(WhPromSq)|BIT(BlPromSq); TraceFunctionEntry(__func__); TraceFunctionParam("%u",index_of_checker); TraceSquare(check_from); TraceFunctionParamListEnd(); if (!TSTFLAGMASK(sq_spec[check_from],prom_square) && GuardDir[Pawn-Pawn][check_from].dir==guard_dir_check_uninterceptable && intelligent_reserve_white_pawn_moves_from_to_checking(checker_from,check_from)) { occupy_square(check_from,Pawn,checker_flags); init_disturb_mate_dir(check_from,being_solved.king_square[Black]-check_from); pipe_solve_delegate(si); fini_disturb_mate_dir(); empty_square(check_from); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_promoted_white_knight(unsigned int placed_index, square placed_on, void (*go_on)(void)) { square const placed_comes_from = white[placed_index].diagram_square; Flags const placed_flags = white[placed_index].flags; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); if (GuardDir[Knight-Pawn][placed_on].dir<guard_dir_guard_uninterceptable && intelligent_reserve_promoting_white_pawn_moves_from_to(placed_comes_from, Knight, placed_on)) { occupy_square(placed_on,Knight,placed_flags); (*go_on)(); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_black_knight(unsigned int placed_index, square placed_on, void (*go_on)(void)) { Flags const placed_flags = black[placed_index].flags; square const placed_comes_from = black[placed_index].diagram_square; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); if ((being_solved.king_square[White]==initsquare || CheckDir[Knight][being_solved.king_square[White]-placed_on]==0) && intelligent_reserve_officer_moves_from_to(Black, placed_comes_from, Knight, placed_on)) { occupy_square(placed_on,Knight,placed_flags); if (DisturbMateDirKnight[placed_on]==0) (*go_on)(); else intelligent_pin_black_piece(placed_on,go_on); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_unpromoted_white_pawn(unsigned int placed_index, square placed_on, void (*go_on)(void)) { square const placed_comes_from = white[placed_index].diagram_square; Flags const placed_flags = white[placed_index].flags; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); if (!TSTFLAGMASK(sq_spec[placed_on],BIT(WhBaseSq)|BIT(WhPromSq)) && GuardDir[Pawn-Pawn][placed_on].dir<guard_dir_guard_uninterceptable && intelligent_reserve_white_pawn_moves_from_to_no_promotion(placed_comes_from, placed_on)) { occupy_square(placed_on,Pawn,placed_flags); (*go_on)(); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_white_knight(unsigned int placed_index, square placed_on, void (*go_on)(void)) { square const placed_comes_from = white[placed_index].diagram_square; Flags const placed_flags = white[placed_index].flags; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); switch (GuardDir[Knight-Pawn][placed_on].dir) { case guard_dir_check_uninterceptable: break; case guard_dir_guard_uninterceptable: if (placed_index>index_of_guarding_piece && intelligent_reserve_officer_moves_from_to(White, placed_comes_from, Knight, placed_on)) { occupy_square(placed_on,Knight,placed_flags); (*go_on)(); intelligent_unreserve(); } break; default: if (intelligent_reserve_officer_moves_from_to(White, placed_comes_from, Knight, placed_on)) { occupy_square(placed_on,Knight,placed_flags); (*go_on)(); intelligent_unreserve(); } break; } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_pinned_black_rider(unsigned int placed_index, square placed_on, void (*go_on)(void)) { piece_walk_type const intercepter_type = black[placed_index].type; Flags const placed_flags = black[placed_index].flags; square const placed_comes_from = black[placed_index].diagram_square; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); { int const check_dir = find_interceptable_check_dir(intercepter_type, placed_on); if (check_dir==0) { if (intelligent_reserve_officer_moves_from_to(Black, placed_comes_from, intercepter_type, placed_on)) { occupy_square(placed_on,intercepter_type,placed_flags); (*go_on)(); intelligent_unreserve(); } } else if (check_dir!=checkdir_uninterceptable && intelligent_reserve_officer_moves_from_to(Black, placed_comes_from, intercepter_type, placed_on)) { occupy_square(placed_on,intercepter_type,placed_flags); intelligent_intercept_check_by_black(check_dir,go_on); intelligent_unreserve(); } } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_mate_generate_checking_moves(slice_index si) { unsigned int index; TraceFunctionEntry(__func__); TraceFunctionParamListEnd(); if (intelligent_reserve_masses(White,1,piece_gives_check)) { for (index = 1; index<MaxPiece[White]; ++index) { square const *bnp; white[index].usage = piece_gives_check; for (bnp = boardnum; *bnp!=initsquare; ++bnp) if (is_square_empty(*bnp)) { switch (white[index].type) { case Queen: case Rook: case Bishop: by_rider(si,index,*bnp); break; case Knight: by_knight(si,index,*bnp); break; case Pawn: by_unpromoted_pawn(si,index,*bnp); by_promoted_pawn(si,index,*bnp); break; default: assert(0); break; } empty_square(*bnp); } white[index].usage = piece_is_unused; } intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_unpromoted_black_pawn(unsigned int placed_index, square placed_on, void (*go_on)(void)) { Flags const placed_flags = black[placed_index].flags; square const placed_comes_from = black[placed_index].diagram_square; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); if (!TSTFLAGMASK(sq_spec[placed_on],BIT(BlBaseSq)|BIT(BlPromSq)) && !black_pawn_attacks_king(placed_on) && intelligent_reserve_black_pawn_moves_from_to_no_promotion(placed_comes_from, placed_on)) { occupy_square(placed_on,Pawn,placed_flags); switch (DisturbMateDirPawn[placed_on]) { case disturbance_by_pawn_capture: case disturbance_by_pawn_interception_single: intelligent_pin_black_piece(placed_on,go_on); break; case disturbance_by_pawn_interception_double: { square const target = placed_on+2*dir_down; assert(is_square_empty(target)); if (is_square_empty(placed_on+dir_down)) { intelligent_intercept_black_move(placed_on,target,go_on); intelligent_pin_black_piece(placed_on,go_on); } else (*go_on)(); break; } default: (*go_on)(); break; } intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
/* Intercept a check to the white king * @param dir_from_rider direction from rider giving check to white king * @param go_on what to do after each successful interception? */ void intelligent_intercept_check_by_black(slice_index si, int dir_from_rider, void (*go_on)(slice_index si)) { TraceFunctionEntry(__func__); TraceFunctionParam("%d",dir_from_rider); TraceFunctionParamListEnd(); if (intelligent_reserve_masses(Black,1,piece_intercepts)) { black_piece(si,dir_from_rider,go_on); intelligent_unreserve(); } if (intelligent_reserve_masses(White,1,piece_intercepts)) { white_piece(si,dir_from_rider,go_on); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
/* Intercept a guard by white * @param target guard of what square * @param dir_from_rider direction from guarding rider * @param go_on what to do after each successful interception? */ void intelligent_intercept_guard_by_white(square target, int dir_from_rider, void (*go_on)(void)) { TraceFunctionEntry(__func__); TraceFunctionParam("%d",dir_from_rider); TraceFunctionParamListEnd(); if (intelligent_reserve_masses(Black,1,piece_intercepts)) { black_piece(target,dir_from_rider,go_on); intelligent_unreserve(); } if (intelligent_reserve_masses(White,1,piece_intercepts)) { white_piece(target,dir_from_rider,go_on); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_white_queen(unsigned int placed_index, square placed_on, void (*go_on)(void)) { piece_walk_type const placed_type = white[placed_index].type; Flags const placed_flags = white[placed_index].flags; square const placed_comes_from = white[placed_index].diagram_square; int const dir_ortho = GuardDir[Rook-Pawn][placed_on].dir; int const dir_diag = GuardDir[Bishop-Pawn][placed_on].dir; TraceFunctionEntry(__func__); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); if (dir_ortho<guard_dir_guard_uninterceptable && dir_diag<guard_dir_guard_uninterceptable && intelligent_reserve_officer_moves_from_to(White, placed_comes_from, placed_type, placed_on)) { square const target_ortho = GuardDir[Rook-Pawn][placed_on].target; stack_elmt_type const new_top = { placed_index, placed_on, go_on, stack_top }; stack_top = &new_top; occupy_square(placed_on,placed_type,placed_flags); if (dir_ortho==0 || TSTFLAG(being_solved.spec[target_ortho],Black) || !is_line_empty(placed_on,target_ortho,dir_ortho)) intercept_queen_diag(); else intelligent_intercept_guard_by_white(target_ortho,dir_ortho,&intercept_queen_diag); assert(stack_top==&new_top); stack_top = stack_top->next; intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }
void intelligent_place_promoted_white_rider(piece_walk_type promotee_type, unsigned int placed_index, square placed_on, void (*go_on)(void)) { square const placed_comes_from = white[placed_index].diagram_square; Flags const placed_flags = white[placed_index].flags; int const dir = GuardDir[promotee_type-Pawn][placed_on].dir; square const target = GuardDir[promotee_type-Pawn][placed_on].target; TraceFunctionEntry(__func__); TraceWalk(promotee_type); TraceFunctionParam("%u",placed_index); TraceSquare(placed_on); TraceFunctionParamListEnd(); if (dir>=guard_dir_guard_uninterceptable) { /* nothing */ } else if (intelligent_reserve_promoting_white_pawn_moves_from_to(placed_comes_from, promotee_type, placed_on)) { occupy_square(placed_on,promotee_type,placed_flags); if (dir==0 || TSTFLAG(being_solved.spec[target],Black) || !is_line_empty(placed_on,target,dir)) (*go_on)(); else intelligent_intercept_guard_by_white(target,dir,go_on); intelligent_unreserve(); } TraceFunctionExit(__func__); TraceFunctionResultEnd(); }