]> git.sesse.net Git - stockfish/commitdiff
Microoptimize generate<MV_EVASION>
authorMarco Costalba <mcostalba@gmail.com>
Thu, 2 Jun 2011 11:14:44 +0000 (12:14 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 2 Jun 2011 11:49:40 +0000 (12:49 +0100)
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/movegen.cpp

index e1e6a54b72aa718c55c9c51bc38416f0d13a4e25..be8753595f529500b755907f64a3e1e9375f4e22 100644 (file)
@@ -272,12 +272,17 @@ MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
       case BISHOP: sliderAttacks |= BishopPseudoAttacks[checksq]; break;
       case ROOK:   sliderAttacks |= RookPseudoAttacks[checksq];   break;
       case QUEEN:
       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<BISHOP>(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<ROOK>(checksq);
           else
               sliderAttacks |= BishopPseudoAttacks[checksq] | pos.attacks_from<ROOK>(checksq);
+
       default:
           break;
       }
       default:
           break;
       }