From: Marco Costalba Date: Fri, 17 Oct 2008 20:52:36 +0000 (+0200) Subject: Movegen: further simplify generate_move_if_legal X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=c852a940094d4f685d7efa4d14ab7e95ddf7ebd2 Movegen: further simplify generate_move_if_legal Signed-off-by: Marco Costalba --- diff --git a/src/movegen.cpp b/src/movegen.cpp index a2e9c9c9..9474bb76 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -712,9 +712,8 @@ Move generate_move_if_legal(const Position &pos, Move m, Bitboard pinned) { return MOVE_NONE; // Proceed according to the type of the moving piece. - switch (type_of_piece(pc)) - { - case PAWN: + if (type_of_piece(pc) == PAWN) + { // If the destination square is on the 8/1th rank, the move must // be a promotion. if ( ( (square_rank(to) == RANK_8 && us == WHITE) @@ -768,43 +767,12 @@ Move generate_move_if_legal(const Position &pos, Move m, Bitboard pinned) { } // The move is pseudo-legal. Return it if it is legal. return (pos.move_is_legal(m) ? m : MOVE_NONE); - break; + } - case KNIGHT: - return ( pos.knight_attacks_square(from, to) - && pos.move_is_legal(m) - && !move_promotion(m) ? m : MOVE_NONE); - break; - - case BISHOP: - return ( pos.bishop_attacks_square(from, to) - && pos.move_is_legal(m) - && !move_promotion(m) ? m : MOVE_NONE); - break; - - case ROOK: - return ( pos.rook_attacks_square(from, to) - && pos.move_is_legal(m) - && !move_promotion(m) ? m : MOVE_NONE); - break; - - case QUEEN: - return ( pos.queen_attacks_square(from, to) - && pos.move_is_legal(m) - && !move_promotion(m) ? m : MOVE_NONE); - break; - - case KING: - return ( pos.king_attacks_square(from, to) - && pos.move_is_legal(m) - && !move_promotion(m) ? m : MOVE_NONE); - break; - - default: - assert(false); - } - assert(false); - return MOVE_NONE; + // Luckly we can handle all the other pieces in one go + return ( pos.piece_attacks_square(from, to) + && pos.move_is_legal(m) + && !move_promotion(m) ? m : MOVE_NONE); } @@ -1039,7 +1007,7 @@ namespace { return n; } - + int generate_knight_moves(const Position &pos, MoveStack *mlist, Color side, Bitboard target) { Square from, to;