+ // Wait until all threads have finished
+ for (Thread* th : Threads)
+ if (th != this)
+ th->wait_for_search_finished();
+
+ // Check if there are threads with a better score than main thread
+ Thread* bestThread = this;
+ if ( !this->easyMovePlayed
+ && Options["MultiPV"] == 1
+ && !Limits.depth
+ && !Skill(Options["Skill Level"]).enabled()
+ && rootMoves[0].pv[0] != MOVE_NONE)
+ {
+ for (Thread* th : Threads)
+ {
+ Depth depthDiff = th->completedDepth - bestThread->completedDepth;
+ Value scoreDiff = th->rootMoves[0].score - bestThread->rootMoves[0].score;
+
+ if (scoreDiff > 0 && depthDiff >= 0)
+ bestThread = th;
+ }
+ }
+
+ previousScore = bestThread->rootMoves[0].score;
+
+ // Send new PV when needed
+ if (bestThread != this)
+ sync_cout << UCI::pv(bestThread->rootPos, bestThread->completedDepth, -VALUE_INFINITE, VALUE_INFINITE) << sync_endl;
+
+ 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());