From 5ff6289afda9cd877e3662f5cc7e6410e1bee999 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Thu, 2 Jun 2011 12:14:44 +0100 Subject: [PATCH] Microoptimize generate No functional change. Signed-off-by: Marco Costalba --- src/movegen.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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; } -- 2.39.2