]> git.sesse.net Git - stockfish/blobdiff - src/movegen.cpp
generate_evasions() avoid to calculate pinned pieces
[stockfish] / src / movegen.cpp
index 9bc149d5103359a802a27d1fd61ad6adba93dded..f30d45720234603fe1dd3b0bec3fef05c5631861 100644 (file)
@@ -40,10 +40,10 @@ namespace {
     QUEEN_SIDE
   };
 
-  static const bool CAPTURE = true;
-  static const bool NON_CAPTURE = false;
+  const bool CAPTURE = true;
+  const bool NON_CAPTURE = false;
 
-  // Function
+  // Functions
   bool castling_is_check(const Position&, CastlingSide);
 
   // Helper templates
@@ -102,7 +102,7 @@ namespace {
 
   template<>
   inline MoveStack* generate_piece_blocking_evasions<PAWN>(const Position& p, MoveStack* m, Color us,
-                                                    Bitboard np, Bitboard bs) {
+                                                           Bitboard np, Bitboard bs) {
     if (us == WHITE)
         return generate_pawn_blocking_evasions<WHITE, RANK_8, Rank3BB, DELTA_N>(p, np, bs, m);
     else
@@ -204,7 +204,7 @@ int generate_checks(const Position& pos, MoveStack* mlist, Bitboard dc) {
 /// only legal moves.  It returns the number of generated moves. This
 /// function is very ugly, and needs cleaning up some time later.  FIXME
 
-int generate_evasions(const Position& pos, MoveStack* mlist) {
+int generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned) {
 
   assert(pos.is_ok());
   assert(pos.is_check());
@@ -265,12 +265,10 @@ int generate_evasions(const Position& pos, MoveStack* mlist) {
   if (!(checkers & (checkers - 1))) // Only one bit set?
   {
       Square checksq = first_1(checkers);
+      Bitboard not_pinned = ~pinned;
 
       assert(pos.color_of_piece_on(checksq) == them);
 
-      // Find pinned pieces
-      Bitboard not_pinned = ~pos.pinned_pieces(us);
-
       // Generate captures of the checking piece
 
       // Pawn captures
@@ -361,15 +359,15 @@ int generate_legal_moves(const Position& pos, MoveStack* mlist) {
 
   assert(pos.is_ok());
 
+  Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
+
   if (pos.is_check())
-      return generate_evasions(pos, mlist);
+      return generate_evasions(pos, mlist, pinned);
 
   // Generate pseudo-legal moves
   int n = generate_captures(pos, mlist);
   n += generate_noncaptures(pos, mlist + n);
 
-  Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
-
   // Remove illegal moves from the list
   for (int i = 0; i < n; i++)
       if (!pos.pl_move_is_legal(mlist[i].move, pinned))
@@ -851,7 +849,7 @@ namespace {
 
     // Double pawn pushes
     b2 = (Us == WHITE ? b1 << 8 : b1 >> 8) & pos.empty_squares() & TRank3BB;
-    b2 = (Us == WHITE ? b2 << 8 : b2 >> 8) & blockSquares;;
+    b2 = (Us == WHITE ? b2 << 8 : b2 >> 8) & blockSquares;
     while (b2)
     {
         to = pop_1st_bit(&b2);