]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Get correct excluded moves for split nodes
[stockfish] / src / search.cpp
index ecfaaa569dfac037a0060187be323d355c37b751..5ae2cf69f54dad439df37f5130245289b1fd0562 100644 (file)
@@ -82,6 +82,7 @@ namespace {
   double BestMoveChanges;
   Value DrawValue[COLOR_NB];
   HistoryStats History;
+  GainsStats Gains;
   CountermovesStats Countermoves;
 
   template <NodeType NT>
@@ -293,6 +294,7 @@ namespace {
     Value bestValue, alpha, beta, delta;
 
     std::memset(ss-2, 0, 5 * sizeof(Stack));
+    (ss-1)->currentMove = MOVE_NULL; // Hack to skip update gains
 
     depth = 0;
     BestMoveChanges = 0;
@@ -301,6 +303,7 @@ namespace {
 
     TT.new_search();
     History.clear();
+    Gains.clear();
     Countermoves.clear();
 
     PVSize = Options["MultiPV"];
@@ -487,9 +490,8 @@ namespace {
     SplitPoint* splitPoint;
     Key posKey;
     Move ttMove, move, excludedMove, bestMove, threatMove;
-    Depth ext, newDepth;
-    Value bestValue, value, ttValue;
-    Value eval, nullValue;
+    Depth ext, newDepth, predictedDepth;
+    Value bestValue, value, ttValue, eval, nullValue, futilityValue;
     bool inCheck, givesCheck, pvMove, singularExtensionNode, improving;
     bool captureOrPromotion, dangerous, doFullDepthSearch;
     int moveCount, quietCount;
@@ -497,6 +499,7 @@ namespace {
     // Step 1. Initialize node
     Thread* thisThread = pos.this_thread();
     inCheck = pos.checkers();
+    excludedMove = ss->excludedMove;
 
     if (SpNode)
     {
@@ -505,7 +508,7 @@ namespace {
         threatMove = splitPoint->threatMove;
         bestValue  = splitPoint->bestValue;
         tte = NULL;
-        ttMove = excludedMove = MOVE_NONE;
+        ttMove = MOVE_NONE;
         ttValue = VALUE_NONE;
 
         assert(splitPoint->bestValue > -VALUE_INFINITE && splitPoint->moveCount > 0);
@@ -545,7 +548,6 @@ namespace {
     // Step 4. Transposition table lookup
     // We don't want the score of a partial search to overwrite a previous full search
     // TT value, so we use a different position key in case of an excluded move.
-    excludedMove = ss->excludedMove;
     posKey = excludedMove ? pos.exclusion_key() : pos.key();
     tte = TT.probe(posKey);
     ttMove = RootNode ? RootMoves[PVIdx].pv[0] : tte ? tte->move() : MOVE_NONE;
@@ -601,6 +603,16 @@ namespace {
         TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->staticEval);
     }
 
+    if (   !pos.captured_piece_type()
+        &&  ss->staticEval != VALUE_NONE
+        && (ss-1)->staticEval != VALUE_NONE
+        && (move = (ss-1)->currentMove) != MOVE_NULL
+        &&  type_of(move) == NORMAL)
+    {
+        Square to = to_sq(move);
+        Gains.update(pos.piece_on(to), to, -(ss-1)->staticEval - ss->staticEval);
+    }
+
     // Step 6. Razoring (skipped when in check)
     if (   !PvNode
         &&  depth < 4 * ONE_PLY
@@ -847,12 +859,13 @@ moves_loop: // When in check and at SpNode search starts from here
               continue;
           }
 
-          Depth predictedDepth = newDepth - reduction<PvNode>(improving, depth, moveCount);
+          predictedDepth = newDepth - reduction<PvNode>(improving, depth, moveCount);
 
           // Futility pruning: parent node
           if (predictedDepth < 7 * ONE_PLY)
           {
-              Value futilityValue = ss->staticEval + futility_margin(predictedDepth) + Value(128);
+              futilityValue = ss->staticEval + futility_margin(predictedDepth)
+                            + Value(128) + Gains[pos.moved_piece(move)][to_sq(move)];
 
               if (futilityValue <= alpha)
               {
@@ -869,8 +882,7 @@ moves_loop: // When in check and at SpNode search starts from here
           }
 
           // Prune moves with negative SEE at low depths
-          if (   predictedDepth < 4 * ONE_PLY
-              && pos.see_sign(move) < 0)
+          if (predictedDepth < 4 * ONE_PLY && pos.see_sign(move) < 0)
           {
               if (SpNode)
                   splitPoint->mutex.lock();
@@ -883,7 +895,7 @@ moves_loop: // When in check and at SpNode search starts from here
       // Check for legality only before to do the move
       if (!RootNode && !SpNode && !pos.legal(move, ci.pinned))
       {
-          --moveCount;
+          moveCount--;
           continue;
       }
 
@@ -1331,7 +1343,7 @@ moves_loop: // When in check and at SpNode search starts from here
     // We exclude the trivial case where a sliding piece does in two moves what
     // it could do in one move: eg. Ra1a2, Ra2a3.
     if (    m2to == m1from
-        || (m1to == m2from && !squares_aligned(m1from, m2from, m2to)))
+        || (m1to == m2from && !aligned(m1from, m2from, m2to)))
         return true;
 
     // Second one moves through the square vacated by first one