From aaffcf973e9c23165ae1aec87c6a2ec1ef29634a Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Mon, 21 Sep 2009 08:47:47 +0100 Subject: [PATCH] Fix a bug in generate_piece_checks() We are generating also king moves that give check ! Of course these moves are illegal so are in any case filtered out in MovePicker. Neverthless we should avoid to generate them. Also simplify a bit the code. No functional change. Signed-off-by: Marco Costalba --- src/movegen.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/movegen.cpp b/src/movegen.cpp index 4e01d418..83f84448 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -848,23 +848,20 @@ namespace { // Direct checks b = target & ~dc; - if (Piece != KING || b) + Bitboard checkSqs = pos.attacks_from(ksq) & pos.empty_squares(); + if (Piece == KING || !checkSqs) + return mlist; + + while (b) { - Bitboard checkSqs = pos.attacks_from(ksq) & pos.empty_squares(); - if (!checkSqs) - return mlist; + Square from = pop_1st_bit(&b); + if ( (Piece == QUEEN && !(QueenPseudoAttacks[from] & checkSqs)) + || (Piece == ROOK && !(RookPseudoAttacks[from] & checkSqs)) + || (Piece == BISHOP && !(BishopPseudoAttacks[from] & checkSqs))) + continue; - while (b) - { - Square from = pop_1st_bit(&b); - if ( (Piece == QUEEN && !(QueenPseudoAttacks[from] & checkSqs)) - || (Piece == ROOK && !(RookPseudoAttacks[from] & checkSqs)) - || (Piece == BISHOP && !(BishopPseudoAttacks[from] & checkSqs))) - continue; - - Bitboard bb = pos.attacks_from(from) & checkSqs; - SERIALIZE_MOVES(bb); - } + Bitboard bb = pos.attacks_from(from) & checkSqs; + SERIALIZE_MOVES(bb); } return mlist; }