]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Retire broken SendSearchedNodes
[stockfish] / src / search.cpp
index d06ca8f3bfd98ed3f4755ad0e0571836ba502b15..4864b1cb151f70e2e1fc1849e198c9abc24802a6 100644 (file)
@@ -175,7 +175,6 @@ namespace {
 
   // Node counters, used only by thread[0] but try to keep in different cache
   // lines (64 bytes each) from the heavy multi-thread read accessed variables.
-  bool SendSearchedNodes;
   int NodesSincePoll;
   int NodesBetweenPolls = 30000;
 
@@ -367,7 +366,7 @@ bool think(Position& pos, const SearchLimits& limits, Move searchMoves[]) {
   static Book book;
 
   // Initialize global search-related variables
-  StopOnPonderhit = StopRequest = QuitRequest = AspirationFailLow = SendSearchedNodes = false;
+  StopOnPonderhit = StopRequest = QuitRequest = AspirationFailLow = false;
   NodesSincePoll = 0;
   current_search_time(get_system_time());
   Limits = limits;
@@ -712,7 +711,7 @@ namespace {
     Depth ext, newDepth;
     ValueType vt;
     Value bestValue, value, oldAlpha;
-    Value refinedValue, nullValue, futilityBase, futilityValueScaled; // Non-PV specific
+    Value refinedValue, nullValue, futilityBase, futilityValue;
     bool isPvMove, inCheck, singularExtensionNode, givesCheck, captureOrPromotion, dangerous;
     int moveCount = 0, playedMoveCount = 0;
     Thread& thread = Threads[pos.thread()];
@@ -995,14 +994,6 @@ split_point_start: // At split points actual search starts from here
           // Save the current node count before the move is searched
           nodes = pos.nodes_searched();
 
-          // If it's time to send nodes info, do it here where we have the
-          // correct accumulated node counts searched by each thread.
-          if (!SpNode && SendSearchedNodes)
-          {
-              SendSearchedNodes = false;
-              cout << "info" << speed_to_uci(pos.nodes_searched()) << endl;
-          }
-
           // For long searches send current move info to GUI
           if (pos.thread() == 0 && current_search_time() > 2000)
               cout << "info" << depth_to_uci(depth)
@@ -1070,19 +1061,19 @@ split_point_start: // At split points actual search starts from here
           // We illogically ignore reduction condition depth >= 3*ONE_PLY for predicted depth,
           // but fixing this made program slightly weaker.
           Depth predictedDepth = newDepth - reduction<PvNode>(depth, moveCount);
-          futilityValueScaled =  futilityBase + futility_margin(predictedDepth, moveCount)
-                               + H.gain(pos.piece_on(move_from(move)), move_to(move));
+          futilityValue =  futilityBase + futility_margin(predictedDepth, moveCount)
+                         + H.gain(pos.piece_on(move_from(move)), move_to(move));
 
-          if (futilityValueScaled < beta)
+          if (futilityValue < beta)
           {
               if (SpNode)
               {
                   lock_grab(&(sp->lock));
-                  if (futilityValueScaled > sp->bestValue)
-                      sp->bestValue = bestValue = futilityValueScaled;
+                  if (futilityValue > sp->bestValue)
+                      sp->bestValue = bestValue = futilityValue;
               }
-              else if (futilityValueScaled > bestValue)
-                  bestValue = futilityValueScaled;
+              else if (futilityValue > bestValue)
+                  bestValue = futilityValue;
 
               continue;
           }
@@ -1228,8 +1219,8 @@ split_point_start: // At split points actual search starts from here
           && Threads.available_slave_exists(pos.thread())
           && !StopRequest
           && !thread.cutoff_occurred())
-          Threads.split<FakeSplit>(pos, ss, &alpha, beta, &bestValue, depth,
-                                   threatMove, moveCount, &mp, NT);
+          bestValue = Threads.split<FakeSplit>(pos, ss, alpha, beta, bestValue, depth,
+                                               threatMove, moveCount, &mp, NT);
     }
 
     // Step 20. Check for mate and stalemate
@@ -1298,6 +1289,7 @@ split_point_start: // At split points actual search starts from here
     bool inCheck, enoughMaterial, givesCheck, evasionPrunable;
     const TTEntry* tte;
     Depth ttDepth;
+    ValueType vt;
     Value oldAlpha = alpha;
 
     ss->bestMove = ss->currentMove = MOVE_NONE;
@@ -1368,7 +1360,7 @@ split_point_start: // At split points actual search starts from here
     CheckInfo ci(pos);
 
     // Loop through the moves until no moves remain or a beta cutoff occurs
-    while (   alpha < beta
+    while (   bestValue < beta
            && (move = mp.get_next_move()) != MOVE_NONE)
     {
       assert(move_is_ok(move));
@@ -1388,10 +1380,11 @@ split_point_start: // At split points actual search starts from here
                          + piece_value_endgame(pos.piece_on(move_to(move)))
                          + (move_is_ep(move) ? PawnValueEndgame : VALUE_ZERO);
 
-          if (futilityValue < alpha)
+          if (futilityValue < beta)
           {
               if (futilityValue > bestValue)
                   bestValue = futilityValue;
+
               continue;
           }
 
@@ -1450,11 +1443,12 @@ split_point_start: // At split points actual search starts from here
       if (value > bestValue)
       {
           bestValue = value;
-          if (value > alpha)
-          {
+          ss->bestMove = move;
+
+          if (   PvNode
+              && value > alpha
+              && value < beta) // We want always alpha < beta
               alpha = value;
-              ss->bestMove = move;
-          }
        }
     }
 
@@ -1464,8 +1458,11 @@ split_point_start: // At split points actual search starts from here
         return value_mated_in(ss->ply);
 
     // Update transposition table
-    ValueType vt = (bestValue <= oldAlpha ? VALUE_TYPE_UPPER : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT);
-    TT.store(pos.get_key(), value_to_tt(bestValue, ss->ply), vt, ttDepth, ss->bestMove, ss->eval, evalMargin);
+    move = bestValue <= oldAlpha ? MOVE_NONE : ss->bestMove;
+    vt   = bestValue <= oldAlpha ? VALUE_TYPE_UPPER
+         : bestValue >= beta ? VALUE_TYPE_LOWER : VALUE_TYPE_EXACT;
+
+    TT.store(pos.get_key(), value_to_tt(bestValue, ss->ply), vt, ttDepth, move, ss->eval, evalMargin);
 
     assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
 
@@ -1945,9 +1942,6 @@ split_point_start: // At split points actual search starts from here
 
         dbg_print_mean();
         dbg_print_hit_rate();
-
-        // Send info on searched nodes as soon as we return to root
-        SendSearchedNodes = true;
     }
 
     // Should we stop the search?