Remove castling moves in check generation
authorMarco Costalba <mcostalba@gmail.com>
Sun, 1 Nov 2009 16:19:04 +0000 (17:19 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 1 Nov 2009 16:19:04 +0000 (17:19 +0100)
Check generation is used only in qsearch and
only at Depth(0), castling moves that give check
are very rare overall and even almost not exsistent
at Depth(0).

So retire this almost never used code that adds
a small but consistent slow down in the normal path.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>

src/movegen.cpp

index cab7c24..00e1adf 100644 (file)
@@ -52,9 +52,6 @@ namespace {
     EVASION
   };
 
-  // Functions
-  bool castling_is_check(const Position&, CastlingSide);
-
   // Helper templates
   template<CastlingSide Side>
   MoveStack* generate_castle_moves(const Position&, MoveStack*);
@@ -190,20 +187,7 @@ MoveStack* generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bi
   mlist = generate_direct_checks<KNIGHT>(pos, mlist, us, dc, ksq);
   mlist = generate_direct_checks<BISHOP>(pos, mlist, us, dc, ksq);
   mlist = generate_direct_checks<ROOK>(pos, mlist, us, dc, ksq);
-  mlist = generate_direct_checks<QUEEN>(pos, mlist, us, dc, ksq);
-
-  // Castling moves that give check. Very rare but nice to have!
-  if (   pos.can_castle_queenside(us)
-      && (square_rank(ksq) == square_rank(pos.king_square(us)) || square_file(ksq) == FILE_D)
-      && castling_is_check(pos, QUEEN_SIDE))
-      mlist = generate_castle_moves<QUEEN_SIDE>(pos, mlist);
-
-  if (   pos.can_castle_kingside(us)
-      && (square_rank(ksq) == square_rank(pos.king_square(us)) || square_file(ksq) == FILE_F)
-      && castling_is_check(pos, KING_SIDE))
-      mlist = generate_castle_moves<KING_SIDE>(pos, mlist);
-
-  return mlist;
+  return  generate_direct_checks<QUEEN>(pos, mlist, us, dc, ksq);
 }
 
 
@@ -787,17 +771,4 @@ namespace {
     }
     return mlist;
   }
-
-  bool castling_is_check(const Position& pos, CastlingSide side) {
-
-    // After castling opponent king is attacked by the castled rook?
-    File rookFile = (side == QUEEN_SIDE ? FILE_D : FILE_F);
-    Color us = pos.side_to_move();
-    Square ksq = pos.king_square(us);
-    Bitboard occ = pos.occupied_squares();
-
-    clear_bit(&occ, ksq); // Remove our king from the board
-    Square rsq = make_square(rookFile, square_rank(ksq));
-    return bit_is_set(rook_attacks_bb(rsq, occ), pos.king_square(opposite_color(us)));
-  }
 }