]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Fix some silly bugs
[stockfish] / src / search.cpp
index 6173a9a4b410d98efb1c9ca3f7fc5646fa8db3b5..6bc77d3ba61224197a72a5ada11e509ef08103c6 100644 (file)
@@ -1359,7 +1359,7 @@ namespace {
     Move ttMove, move;
     Depth ext, newDepth;
     Value bestValue, staticValue, nullValue, value, futilityValue, futilityValueScaled;
-    bool isCheck, useFutilityPruning, singleEvasion, moveIsCheck, captureOrPromotion, dangerous;
+    bool isCheck, singleEvasion, moveIsCheck, captureOrPromotion, dangerous;
     bool mateThreat = false;
     int moveCount = 0;
     futilityValue = staticValue = bestValue = value = -VALUE_INFINITE;
@@ -1430,7 +1430,7 @@ namespace {
     }
 
     // Post futility pruning
-    if (staticValue - PostFutilityValueMargin >= beta)
+    if (depth < SelectiveDepth && staticValue - PostFutilityValueMargin >= beta)
         return (staticValue - PostFutilityValueMargin);
 
     // Null move search
@@ -1510,7 +1510,6 @@ namespace {
     // to search all moves.
     MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]);
     CheckInfo ci(pos);
-    useFutilityPruning = depth < SelectiveDepth && !isCheck;
 
     // Loop through all legal moves until no moves remain or a beta cutoff occurs
     while (   bestValue < beta
@@ -1556,8 +1555,31 @@ namespace {
       // Update current move
       movesSearched[moveCount++] = ss[ply].currentMove = move;
 
+      // Futility pruning for captures
+      Color them = opposite_color(pos.side_to_move());
+
+      if (   !isCheck
+          && newDepth < SelectiveDepth
+          && !dangerous
+          && pos.move_is_capture(move)
+          && !pos.move_is_check(move, ci)
+          && !move_is_promotion(move)
+          && move != ttMove
+          && !move_is_ep(move)
+          && (pos.type_of_piece_on(move_to(move)) != PAWN || !pos.pawn_is_passed(them, move_to(move)))) // Do not prune passed pawn captures
+      {
+          int preFutilityValueMargin = 0;
+
+          if (newDepth >= OnePly)
+              preFutilityValueMargin = 112 * bitScanReverse32(int(newDepth) * int(newDepth) / 2);
+
+          if (ss[ply].eval + pos.endgame_value_of_piece_on(move_to(move)) + preFutilityValueMargin + ei.futilityMargin + 90 < beta)
+              continue;
+      }
+
+
       // Futility pruning
-      if (    useFutilityPruning
+      if (   !isCheck
           && !dangerous
           && !captureOrPromotion
           && !move_is_castle(move)
@@ -1577,19 +1599,22 @@ namespace {
           if (red >= 1.0)
               predictedDepth -= int(floor(red * int(OnePly)));
 
-          int preFutilityValueMargin = 0;
-          if (predictedDepth >= OnePly)
-              preFutilityValueMargin = 112 * bitScanReverse32(int(predictedDepth) * int(predictedDepth) / 2);
+          if (predictedDepth < SelectiveDepth)
+          {
+              int preFutilityValueMargin = 0;
+              if (predictedDepth >= OnePly)
+                  preFutilityValueMargin = 112 * bitScanReverse32(int(predictedDepth) * int(predictedDepth) / 2);
 
-          preFutilityValueMargin += MG.retrieve(pos.piece_on(move_from(move)), move_from(move), move_to(move)) + 45;
+              preFutilityValueMargin += MG.retrieve(pos.piece_on(move_from(move)), move_from(move), move_to(move)) + 45;
 
-          futilityValueScaled = ss[ply].eval + preFutilityValueMargin - moveCount * IncrementalFutilityMargin;
+              futilityValueScaled = ss[ply].eval + preFutilityValueMargin - moveCount * IncrementalFutilityMargin;
 
-          if (futilityValueScaled < beta)
-          {
-              if (futilityValueScaled > bestValue)
-                  bestValue = futilityValueScaled;
-              continue;
+              if (futilityValueScaled < beta)
+              {
+                  if (futilityValueScaled > bestValue)
+                      bestValue = futilityValueScaled;
+                  continue;
+              }
           }
       }