From: Marco Costalba Date: Thu, 2 Jun 2011 11:14:44 +0000 (+0100) Subject: Microoptimize generate X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=5ff6289afda9cd877e3662f5cc7e6410e1bee999 Microoptimize generate No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/movegen.cpp b/src/movegen.cpp index e1e6a54b..be875359 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -272,12 +272,17 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { case BISHOP: sliderAttacks |= BishopPseudoAttacks[checksq]; break; case ROOK: sliderAttacks |= RookPseudoAttacks[checksq]; break; case QUEEN: - // In case of a queen remove also squares attacked in the other direction to - // avoid possible illegal moves when queen and king are on adjacent squares. - if (RookPseudoAttacks[checksq] & (1ULL << ksq)) - sliderAttacks |= RookPseudoAttacks[checksq] | pos.attacks_from(checksq); + // If queen and king are far we can safely remove all the squares attacked + // in the other direction becuase are not reachable by the king anyway. + if (squares_between(ksq, checksq) || (RookPseudoAttacks[checksq] & (1ULL << ksq))) + sliderAttacks |= QueenPseudoAttacks[checksq]; + + // Otherwise, if king and queen are adjacent and on a diagonal line, we need to + // use real rook attacks to check if king is safe to move in the other direction. + // For example: king in B2, queen in A1 a knight in B1, and we can safely move to C1. else sliderAttacks |= BishopPseudoAttacks[checksq] | pos.attacks_from(checksq); + default: break; }