Avoid to call useless sliders attacks in update_checkers()
authorMarco Costalba <mcostalba@gmail.com>
Wed, 4 Mar 2009 13:50:39 +0000 (14:50 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 4 Mar 2009 21:51:04 +0000 (22:51 +0100)
Quickly filter out some calls to sliders attacks
when we already know that will fail for sure.

No functional change.

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

index 21839d6abaf32e52e48d027e4a9b626864496fc3..65964b827a889880ca1d8322e7c339d0b81494bc 100644 (file)
@@ -648,7 +648,18 @@ template<PieceType Piece>
 inline void Position::update_checkers(Bitboard* pCheckersBB, Square ksq, Square from,
                                       Square to, Bitboard dcCandidates) {
 
-  if (Piece != KING && bit_is_set(piece_attacks<Piece>(ksq), to))
+  const bool Bishop = (Piece == QUEEN || Piece == BISHOP);
+  const bool Rook   = (Piece == QUEEN || Piece == ROOK);
+  const bool Slider = Bishop || Rook;
+
+  if (  (   (Bishop && bit_is_set(BishopPseudoAttacks[ksq], to))
+         || (Rook   && bit_is_set(RookPseudoAttacks[ksq], to)))
+      && bit_is_set(piece_attacks<Piece>(ksq), to)) // slow, try to early skip
+      set_bit(pCheckersBB, to);
+
+  else if (   Piece != KING
+           && !Slider
+           && bit_is_set(piece_attacks<Piece>(ksq), to))
       set_bit(pCheckersBB, to);
 
   if (Piece != QUEEN && bit_is_set(dcCandidates, from))