]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Fix random moves when time < 10ms
[stockfish] / src / search.cpp
index 24f1e6245672be6b230e8d63d9484d811e30b2d6..4b0a9fe8b60676b96c7c5dcc9bda19f9d5bcd6b8 100644 (file)
@@ -242,13 +242,11 @@ void Search::think() {
   Threads.sleepWhileIdle = Options["Idle Threads Sleep"];
 
   // Set best timer interval to avoid lagging under time pressure. Timer is
-  // used to check for remaining available thinking time.
+  // used to check for remaining available thinking time. Timer will be started
+  // at the end of first iteration to avoid returning with a random move.
   Threads.timer->msec =
   Limits.use_time_management() ? std::min(100, std::max(TimeMgr.available_time() / 16, TimerResolution)) :
-                  Limits.nodes ? 2 * TimerResolution
-                               : 100;
-
-  Threads.timer->notify_one(); // Wake up the recurring timer
+                  Limits.nodes ? 2 * TimerResolution : 100;
 
   id_loop(RootPos); // Let's start searching !
 
@@ -402,6 +400,10 @@ namespace {
                 assert(alpha >= -VALUE_INFINITE && beta <= VALUE_INFINITE);
             }
 
+            // Wake up the recurring timer after first iteration is finished
+            if (depth == 1)
+                Threads.timer->notify_one();
+
             // Sort the PV lines searched so far and update the GUI
             std::stable_sort(RootMoves.begin(), RootMoves.begin() + PVIdx + 1);