Skip to content

Commit

Permalink
Pick bestmove from the deepest thread.
Browse files Browse the repository at this point in the history
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 official-stockfish#485
  • Loading branch information
mbootsector authored and zamar committed Nov 2, 2015
1 parent 86f04db commit 27c5cb5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -352,6 +364,7 @@ void Thread::search(bool isMainThread) {

bestValue = delta = alpha = -VALUE_INFINITE;
beta = VALUE_INFINITE;
completedDepth = DEPTH_ZERO;

if (isMainThread)
{
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct Thread : public ThreadBase {
Depth rootDepth;
HistoryStats history;
MovesStats counterMoves;
Depth completedDepth;
};


Expand Down

0 comments on commit 27c5cb5

Please sign in to comment.