Skip to content

Commit d60f5de

Browse files
committed
Fix bestThread selection
If multiple threads have the same best move, pick the thread with the largest contribution to the confidence vote. This thread will later be used to display PV, so this patch is about user-friendliness and/or least surprises, it non-functional for playing strenght. closes #4246 No functional change
1 parent c7118fb commit d60f5de

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/thread.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,14 @@ Thread* ThreadPool::get_best_thread() const {
221221
minScore = std::min(minScore, th->rootMoves[0].score);
222222

223223
// Vote according to score and depth, and select the best thread
224+
auto thread_value = [minScore](Thread* th) {
225+
return (th->rootMoves[0].score - minScore + 14) * int(th->completedDepth);
226+
};
227+
224228
for (Thread* th : *this)
225-
{
226-
votes[th->rootMoves[0].pv[0]] +=
227-
(th->rootMoves[0].score - minScore + 14) * int(th->completedDepth);
229+
votes[th->rootMoves[0].pv[0]] += thread_value(th);
228230

231+
for (Thread* th : *this)
229232
if (abs(bestThread->rootMoves[0].score) >= VALUE_TB_WIN_IN_MAX_PLY)
230233
{
231234
// Make sure we pick the shortest mate / TB conversion or stave off mate the longest
@@ -236,9 +239,8 @@ Thread* ThreadPool::get_best_thread() const {
236239
|| ( th->rootMoves[0].score > VALUE_TB_LOSS_IN_MAX_PLY
237240
&& ( votes[th->rootMoves[0].pv[0]] > votes[bestThread->rootMoves[0].pv[0]]
238241
|| ( votes[th->rootMoves[0].pv[0]] == votes[bestThread->rootMoves[0].pv[0]]
239-
&& th->rootMoves[0].pv.size() > bestThread->rootMoves[0].pv.size()))))
242+
&& thread_value(th) > thread_value(bestThread)))))
240243
bestThread = th;
241-
}
242244

243245
return bestThread;
244246
}

0 commit comments

Comments
 (0)