]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Generalize shift_bb() to handle double pushes
[stockfish] / src / evaluate.cpp
index 6ec42e24e9a0c602e50b2838857bc49449106060..b1422ac67eccb50fefdebde17d7396d01b0542db 100644 (file)
@@ -633,19 +633,17 @@ namespace {
                 else
                     defendedSquares = squaresToQueen & ei.attackedBy[Us][ALL_PIECES];
 
-                // If there aren't any enemy attacks, then assign a huge bonus.
-                // The bonus will be a bit smaller if at least the block square
-                // isn't attacked, otherwise assign the smallest possible bonus.
-                int k = !unsafeSquares ? 15 : !(unsafeSquares & blockSq) ? 9 : 3;
-
-                // Assign a big bonus if the path to the queen is fully defended,
-                // otherwise assign a bit less of a bonus if at least the block
-                // square is defended.
+                // If there aren't any enemy attacks, assign a big bonus. Otherwise
+                // assign a smaller bonus if the block square isn't attacked.
+                int k = !unsafeSquares ? 15 : !(unsafeSquares & blockSq) ? 9 : 0;
+
+                // If the path to queen is fully defended, assign a big bonus.
+                // Otherwise assign a smaller bonus if the block square is defended.
                 if (defendedSquares == squaresToQueen)
                     k += 6;
 
                 else if (defendedSquares & blockSq)
-                    k += (unsafeSquares & defendedSquares) == unsafeSquares ? 4 : 2;
+                    k += 4;
 
                 mbonus += Value(k * rr), ebonus += Value(k * rr);
             }
@@ -704,7 +702,9 @@ namespace {
   template<Color Us>
   int evaluate_space(const Position& pos, const EvalInfo& ei) {
 
-    const Color Them = (Us == WHITE ? BLACK : WHITE);
+    const Color  Them     = (Us == WHITE ? BLACK    : WHITE);
+    const Square Down     = (Us == WHITE ? DELTA_S  : DELTA_N);
+    const Square DownDown = (Us == WHITE ? DELTA_SS : DELTA_NN);
 
     // Find the safe squares for our pieces inside the area defined by
     // SpaceMask[]. A square is unsafe if it is attacked by an enemy
@@ -716,8 +716,8 @@ namespace {
 
     // Find all squares which are at most three squares behind some friendly pawn
     Bitboard behind = pos.pieces(Us, PAWN);
-    behind |= (Us == WHITE ? behind >>  8 : behind <<  8);
-    behind |= (Us == WHITE ? behind >> 16 : behind << 16);
+    behind |= shift_bb<    Down>(behind);
+    behind |= shift_bb<DownDown>(behind);
 
     // Since SpaceMask[Us] is fully on our half of the board
     assert(unsigned(safe >> (Us == WHITE ? 32 : 0)) == 0);