]> git.sesse.net Git - stockfish/commitdiff
Pick bestmove from the deepest thread.
authormbootsector <mbootsector@gmail.com>
Mon, 2 Nov 2015 09:58:18 +0000 (09:58 +0000)
committerJoona Kiiski <joona@zoox.com>
Mon, 2 Nov 2015 10:05:43 +0000 (10:05 +0000)
STC:
LLR: 2.96 (-2.94,2.94) [0.00,5.00]
Total: 26930 W: 4441 L: 4214 D: 18275

LTC:
LLR: 2.96 (-2.94,2.94) [0.00,5.00]
Total: 7783 W: 1017 L: 876 D: 5890

No functional change in single thread mode

Resolves #485

src/search.cpp
src/thread.h

index 380c334291e3b79a0d30dfd74c37ffb0e41616de..39a731936f4b6e2b59bea6c203a31c643a0f9c62 100644 (file)
@@ -329,10 +329,22 @@ void MainThread::think() {
       wait(Signals.stop);
   }
 
-  sync_cout << "bestmove " << UCI::move(rootMoves[0].pv[0], rootPos.is_chess960());
+  // Check if there are threads with a better score than main thread.
+  Thread* bestThread = this;
+  for (Thread* th : Threads)
+      if (   th->completedDepth > bestThread->completedDepth
+          && th->rootMoves[0].score > bestThread->rootMoves[0].score)
+        bestThread = th;
+
+  // Send new PV when needed.
+  // FIXME: Breaks multiPV, and skill levels
+  if (bestThread != this)
+      sync_cout << UCI::pv(bestThread->rootPos, bestThread->completedDepth, -VALUE_INFINITE, VALUE_INFINITE) << sync_endl;
 
-  if (rootMoves[0].pv.size() > 1 || rootMoves[0].extract_ponder_from_tt(rootPos))
-      std::cout << " ponder " << UCI::move(rootMoves[0].pv[1], rootPos.is_chess960());
+  sync_cout << "bestmove " << UCI::move(bestThread->rootMoves[0].pv[0], rootPos.is_chess960());
+
+  if (bestThread->rootMoves[0].pv.size() > 1 || bestThread->rootMoves[0].extract_ponder_from_tt(rootPos))
+      std::cout << " ponder " << UCI::move(bestThread->rootMoves[0].pv[1], rootPos.is_chess960());
 
   std::cout << sync_endl;
 }
@@ -352,6 +364,7 @@ void Thread::search(bool isMainThread) {
 
   bestValue = delta = alpha = -VALUE_INFINITE;
   beta = VALUE_INFINITE;
+  completedDepth = DEPTH_ZERO;
 
   if (isMainThread)
   {
@@ -472,6 +485,9 @@ void Thread::search(bool isMainThread) {
               sync_cout << UCI::pv(rootPos, rootDepth, alpha, beta) << sync_endl;
       }
 
+      if (!Signals.stop)
+          completedDepth = rootDepth;
+
       if (!isMainThread)
           continue;
 
index c1e553223066d147c86c0aa2e1ea330a704dea96..fd7343a8f57a1d9d2bc0f1c40f27c94ad1148098 100644 (file)
@@ -76,6 +76,7 @@ struct Thread : public ThreadBase {
   Depth rootDepth;
   HistoryStats history;
   MovesStats counterMoves;
+  Depth completedDepth;
 };