]> git.sesse.net Git - stockfish/commitdiff
Simplify generate<EVASIONS>
authorMarco Costalba <mcostalba@gmail.com>
Mon, 11 Nov 2013 18:48:29 +0000 (19:48 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 11 Nov 2013 18:53:19 +0000 (19:53 +0100)
Use the newly introduced LineBB[] to simplify this
super hot-path function.

Verified with perft we don't have any speed regression, although
the number of squares removed is less than before in case of
contact check.

Insipred by DiscoCheck implementation.

Perft numbers are the same, but we have an harmless functional
change due to reorder of moves, because now some illegal moves
are no more detected at generation time, but in the search.

bench: 8331357

src/movegen.cpp

index a254590b1286fa8aa02a529d915c377f90c9efe1..a3623a69e5e4369bfcfcae701e04cdce4c2d82d0 100644 (file)
@@ -364,26 +364,9 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* mlist) {
 
       assert(color_of(pos.piece_on(checksq)) == ~us);
 
-      switch (type_of(pos.piece_on(checksq)))
-      {
-      case BISHOP: sliderAttacks |= PseudoAttacks[BISHOP][checksq]; break;
-      case ROOK:   sliderAttacks |= PseudoAttacks[ROOK][checksq];   break;
-      case QUEEN:
-          // If queen and king are far or not on a diagonal line we can safely
-          // remove all the squares attacked in the other direction becuase are
-          // not reachable by the king anyway.
-          if (between_bb(ksq, checksq) || !(PseudoAttacks[BISHOP][checksq] & ksq))
-              sliderAttacks |= PseudoAttacks[QUEEN][checksq];
-
-          // Otherwise 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 |= PseudoAttacks[BISHOP][checksq] | pos.attacks_from<ROOK>(checksq);
-
-      default:
-          break;
-      }
+      if (type_of(pos.piece_on(checksq)) > KNIGHT) // A slider
+          sliderAttacks |= LineBB[checksq][ksq] ^ checksq;
+
   } while (b);
 
   // Generate evasions for king, capture and non capture moves