/* Generate legal moves for king as if it were a knight and return TRUE if king * is in check by these pieces. */ int player_check_by_knight (int start_pos, int player, int *moves_array) { /* Pretend king is a knight and generate moves. If king can then attack an * enemy's knight, king is in check. */ init_moves_board (moves_array); gen_knight_moves (player, start_pos, moves_array); int mod = (player == BPLAYER) ? 1 : -1; int i; for (i = 0; i < BOARD_SIZE; i++) { if ((moves_array[i] == TRUE) && (board[i] == chp_wknight * mod)) { return TRUE; } } return FALSE; }
template<Color Us, GenType Type> FORCE_INLINE ExtMove* generate_all(const Position& pos, ExtMove* mlist, Bitboard target, const CheckInfo* ci = NULL) { const bool Checks = Type == QUIET_CHECKS; mlist = gen_rook_moves(pos, mlist,target); mlist = gen_knight_moves(pos, mlist,target); mlist = gen_cannon_moves(pos, mlist,target); mlist = gen_pawn_moves<Us>(pos, mlist,target); mlist = gen_bishop_moves(pos, mlist,target); mlist = gen_advisor_moves(pos, mlist,target); if(QUIET_CHECKS != Type) mlist = gen_king_moves(pos, mlist,target); return mlist; }
/* Generate pseudo legal moves at START_POS and store in MOVES_ARRAY. */ void gen_plegal_moves (int player, int start_pos, int *moves_array) { switch (board[start_pos]) { case chp_wpawn: gen_wpawn_moves (start_pos, moves_array); break; case chp_bpawn: gen_bpawn_moves (start_pos, moves_array); break; case chp_wknight: case chp_bknight: gen_knight_moves (player, start_pos, moves_array); break; case chp_wking: case chp_bking: gen_king_moves (player, start_pos, moves_array); break; case chp_wrook: case chp_brook: gen_rook_moves (player, start_pos, moves_array); break; case chp_wbishop: case chp_bbishop: gen_bishop_moves (player, start_pos, moves_array); break; case chp_wqueen: case chp_bqueen: gen_queen_moves (player, start_pos, moves_array); break; } }