]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Don't prune discovered checks
[stockfish] / src / search.cpp
index 35160b9665a39d6ed99bae69da65940ebf9f049b..35a396814d676f4878738150ddd129d20e551bb1 100644 (file)
@@ -62,10 +62,6 @@ namespace {
   // Different node types, used as template parameter
   enum NodeType { Root, PV, NonPV, SplitPointRoot, SplitPointPV, SplitPointNonPV };
 
-  // Lookup table to check if a Piece is a slider and its access function
-  const bool Slidings[18] = { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1 };
-  inline bool piece_is_slider(Piece p) { return Slidings[p]; }
-
   // Dynamic razoring margin based on depth
   inline Value razor_margin(Depth d) { return Value(512 + 16 * int(d)); }
 
@@ -487,7 +483,8 @@ namespace {
     Depth ext, newDepth;
     Value bestValue, value, ttValue;
     Value eval, nullValue, futilityValue;
-    bool inCheck, givesCheck, pvMove, singularExtensionNode;
+    CheckType givesCheck;
+    bool inCheck, pvMove, singularExtensionNode;
     bool captureOrPromotion, dangerous, doFullDepthSearch;
     int moveCount, playedMoveCount;
 
@@ -819,7 +816,7 @@ split_point_start: // At split points actual search starts from here
       if (PvNode && dangerous)
           ext = ONE_PLY;
 
-      else if (givesCheck && pos.see_sign(move) >= 0)
+      else if (givesCheck && (givesCheck == DISCO_CHECK || pos.see_sign(move) >= 0))
           ext = ONE_PLY / 2;
 
       // Singular extension search. If all moves but one fail low on a search of
@@ -886,6 +883,7 @@ split_point_start: // At split points actual search starts from here
 
           // Prune moves with negative SEE at low depths
           if (   predictedDepth < 2 * ONE_PLY
+              && givesCheck != DISCO_CHECK
               && pos.see_sign(move) < 0)
           {
               if (SpNode)
@@ -1020,8 +1018,12 @@ split_point_start: // At split points actual search starts from here
           &&  depth >= Threads.min_split_depth()
           &&  bestValue < beta
           &&  Threads.available_slave_exists(thisThread))
+      {
           bestValue = Threads.split<FakeSplit>(pos, ss, alpha, beta, bestValue, &bestMove,
                                                depth, threatMove, moveCount, mp, NT);
+          if (bestValue >= beta)
+              break;
+      }
     }
 
     if (SpNode)
@@ -1102,11 +1104,13 @@ split_point_start: // At split points actual search starts from here
     Key posKey;
     Move ttMove, move, bestMove;
     Value bestValue, value, ttValue, futilityValue, futilityBase;
-    bool givesCheck, enoughMaterial, evasionPrunable;
+    CheckType givesCheck;
+    bool enoughMaterial, evasionPrunable, fromNull;
     Depth ttDepth;
 
     ss->currentMove = bestMove = MOVE_NONE;
     ss->ply = (ss-1)->ply + 1;
+    fromNull = (ss-1)->currentMove == MOVE_NULL;
 
     // Check for an instant draw or maximum ply reached
     if (pos.is_draw<false, false>() || ss->ply > MAX_PLY)
@@ -1144,7 +1148,12 @@ split_point_start: // At split points actual search starts from here
     }
     else
     {
-        if (tte)
+        if (fromNull)
+        {
+            ss->staticEval = bestValue = -(ss-1)->staticEval;
+            ss->evalMargin = VALUE_ZERO;
+        }
+        else if (tte)
         {
             assert(tte->static_value() != VALUE_NONE || Threads.size() > 1);
 
@@ -1192,6 +1201,7 @@ split_point_start: // At split points actual search starts from here
       if (   !PvNode
           && !InCheck
           && !givesCheck
+          && !fromNull
           &&  move != ttMove
           &&  enoughMaterial
           &&  type_of(move) != PROMOTION
@@ -1227,6 +1237,7 @@ split_point_start: // At split points actual search starts from here
       if (   !PvNode
           && (!InCheck || evasionPrunable)
           &&  move != ttMove
+          &&  givesCheck != DISCO_CHECK
           &&  type_of(move) != PROMOTION
           &&  pos.see_sign(move) < 0)
           continue;
@@ -1437,10 +1448,8 @@ split_point_start: // At split points actual search starts from here
             return true;
     }
 
-    // If the threat piece is a slider, don't prune safe moves which block it
-    if (    piece_is_slider(pos.piece_on(tfrom))
-        && (between_bb(tfrom, tto) & mto)
-        &&  pos.see_sign(move) >= 0)
+    // Don't prune safe moves which block the threat path
+    if ((between_bb(tfrom, tto) & mto) && pos.see_sign(move) >= 0)
         return true;
 
     return false;