]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Introduce MovePicker::isBadCapture() and use in probcut
[stockfish] / src / search.cpp
index 58a82d9dc24699cf04ad76b8b3dae4d40a44ec71..2fdd2840ea2b38915c453baf46783cc097909b35 100644 (file)
@@ -681,7 +681,7 @@ namespace {
     ValueType vt;
     Value bestValue, value, oldAlpha;
     Value refinedValue, nullValue, futilityBase, futilityValueScaled; // Non-PV specific
-    bool isPvMove, inCheck, singularExtensionNode, givesCheck, captureOrPromotion, dangerous, isBadCap;
+    bool isPvMove, inCheck, singularExtensionNode, givesCheck, captureOrPromotion, dangerous;
     int moveCount = 0, playedMoveCount = 0;
     int threadID = pos.thread();
     SplitPoint* sp = NULL;
@@ -871,8 +871,8 @@ namespace {
         search<PvNode>(pos, ss, alpha, beta, d);
         ss->skipNullMove = false;
 
-        ttMove = ss->bestMove;
         tte = TT.probe(posKey);
+        ttMove = tte ? tte->move() : MOVE_NONE;
     }
 
 split_point_start: // At split points actual search starts from here
@@ -885,8 +885,7 @@ split_point_start: // At split points actual search starts from here
     singularExtensionNode =   !Root
                            && !SpNode
                            && depth >= SingularExtensionDepth[PvNode]
-                           && tte
-                           && tte->move()
+                           && ttMove != MOVE_NONE
                            && !excludedMove // Do not allow recursive singular extension search
                            && (tte->type() & VALUE_TYPE_LOWER)
                            && tte->depth() >= depth - 3 * ONE_PLY;
@@ -938,7 +937,7 @@ split_point_start: // At split points actual search starts from here
       // At Root and at first iteration do a PV search on all the moves to score root moves
       isPvMove = (PvNode && moveCount <= (Root ? depth <= ONE_PLY ? 1000 : MultiPV : 1));
       givesCheck = pos.move_gives_check(move, ci);
-      captureOrPromotion = pos.move_is_capture_or_promotion(move);
+      captureOrPromotion = pos.move_is_capture(move) || move_is_promotion(move);
 
       // Step 11. Decide the new search depth
       ext = extension<PvNode>(pos, move, captureOrPromotion, givesCheck, &dangerous);
@@ -949,7 +948,7 @@ split_point_start: // At split points actual search starts from here
       // on all the other moves but the ttMove, if result is lower than ttValue minus
       // a margin then we extend ttMove.
       if (   singularExtensionNode
-          && move == tte->move()
+          && move == ttMove
           && ext < ONE_PLY)
       {
           Value ttValue = value_from_tt(tte->value(), ss->ply);
@@ -1024,16 +1023,6 @@ split_point_start: // At split points actual search starts from here
           }
       }
 
-      // Bad capture detection. Will be used by prob-cut search
-      isBadCap =   depth >= 3 * ONE_PLY
-                && depth < 8 * ONE_PLY
-                && captureOrPromotion
-                && move != ttMove
-                && !dangerous
-                && !move_is_promotion(move)
-                &&  abs(alpha) < VALUE_MATE_IN_PLY_MAX
-                &&  pos.see_sign(move) < 0;
-
       // Step 13. Make the move
       pos.do_move(move, st, ci, givesCheck);
 
@@ -1077,7 +1066,13 @@ split_point_start: // At split points actual search starts from here
 
           // Probcut search for bad captures. If a reduced search returns a value
           // very below beta then we can (almost) safely prune the bad capture.
-          if (isBadCap)
+          if (   depth >= 3 * ONE_PLY
+              && depth < 8 * ONE_PLY
+              && mp.isBadCapture()
+              && move != ttMove
+              && !dangerous
+              && !move_is_promotion(move)
+              &&  abs(alpha) < VALUE_MATE_IN_PLY_MAX)
           {
               ss->reduction = 3 * ONE_PLY;
               Value rAlpha = alpha - 300;
@@ -1216,7 +1211,8 @@ split_point_start: // At split points actual search starts from here
 
         // Update killers and history only for non capture moves that fails high
         if (    bestValue >= beta
-            && !pos.move_is_capture_or_promotion(move))
+            && !pos.move_is_capture(move)
+            && !move_is_promotion(move))
         {
             if (move != ss->killers[0])
             {
@@ -1384,7 +1380,8 @@ split_point_start: // At split points actual search starts from here
           && !inCheck
           &&  givesCheck
           &&  move != ttMove
-          && !pos.move_is_capture_or_promotion(move)
+          && !pos.move_is_capture(move)
+          && !move_is_promotion(move)
           &&  ss->eval + PawnValueMidgame / 4 < beta
           && !check_is_dangerous(pos, move, futilityBase, beta, &bestValue))
       {
@@ -1627,7 +1624,7 @@ split_point_start: // At split points actual search starts from here
     assert(move_is_ok(m));
     assert(threat && move_is_ok(threat));
     assert(!pos.move_gives_check(m));
-    assert(!pos.move_is_capture_or_promotion(m));
+    assert(!pos.move_is_capture(m) && !move_is_promotion(m));
     assert(!pos.move_is_passed_pawn_push(m));
 
     Square mfrom, mto, tfrom, tto;