From: mstembera Date: Mon, 8 Jul 2019 01:36:57 +0000 (-0700) Subject: Bug fix: always choose shortest mate in multithread mode X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=9d3a2ecaa22cb55bddef0e932f2b2951cf6cacf5 Bug fix: always choose shortest mate in multithread mode In current master, with the voting scheme the best thread selection may pick a non mate or not the shortest mate thread. This patch fixes this bug. Formatting suggestion by Jörg Oster. Related past pull requests: https://github.com/official-stockfish/Stockfish/pull/1074 https://github.com/official-stockfish/Stockfish/pull/1215 Passed a [-4..0] verification test with 3 threads: LLR: 2.95 (-2.94,2.94) [-4.00,0.00] Total: 57158 W: 11374 L: 11424 D: 34360 http://tests.stockfishchess.org/tests/view/5d22deb30ebc5925cf0caefd Closes https://github.com/official-stockfish/Stockfish/pull/2226 No functional change (in single threaded mode) ---------------------------------------------------- Comment by Jörg Oster Just one sample output to demonstrate the effect of this patch. 5 Threads, 1 GB Hash +---+---+---+---+---+---+---+---+ | r | | b | | | r | k | | +---+---+---+---+---+---+---+---+ | | | | n | | p | b | | +---+---+---+---+---+---+---+---+ | | | p | | p | | p | | +---+---+---+---+---+---+---+---+ | p | | | | | | P | | +---+---+---+---+---+---+---+---+ | P | p | | | B | | N | Q | +---+---+---+---+---+---+---+---+ | | q | | | | | P | | +---+---+---+---+---+---+---+---+ | | | R | | | P | | | +---+---+---+---+---+---+---+---+ | | | | R | | | K | | +---+---+---+---+---+---+---+---+ Fen: r1b2rk1/3n1pb1/2p1p1p1/p5P1/Pp2B1NQ/1q4P1/2R2P2/3R2K1 w - - 8 34 Key: 38B4CA1067D4F477 Checkers: ucinewgame isready readyok go mate 17 searchmoves d1d7 info depth 65 seldepth 36 multipv 1 score mate 18 nodes 785875935 nps 8650448 hashfull 1000 tbhits 0 time 90848 pv d1d7 c8d7 g4f6 g7f6 g5f6 b3a3 g1g2 a3a1 h4g5 a1f6 g5f6 e6e5 c2c1 d7h3 g2h3 a8a6 h3g2 c6c5 f6a6 g8g7 c1c5 f7f6 a6e6 f8f7 c5c8 f6f5 e4d5 g7h6 e6f7 f5f4 f7e7 f4f3 d5f3 b4b3 c8h8 info depth 63 seldepth 36 multipv 1 score mate 17 nodes 785875935 nps 8650448 hashfull 1000 tbhits 0 time 90848 pv d1d7 c8d7 g4f6 g7f6 g5f6 b3a3 g1g2 a3a1 h4g5 a1f6 g5f6 e6e5 c2c1 d7h3 g2h3 a8a6 c1d1 b4b3 h3g2 c6c5 f6a6 g8g7 d1d7 g7g8 a6f6 b3b2 e4g6 b2b1q g6f7 f8f7 f6f7 g8h8 f7g7 bestmove d1d7 ponder c8d7 --- diff --git a/src/search.cpp b/src/search.cpp index 09df1ac2..eda7f2f7 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -277,7 +277,7 @@ void MainThread::search() { std::map votes; Value minScore = this->rootMoves[0].score; - // Find out minimum score and reset votes for moves which can be voted + // Find out minimum score for (Thread* th: Threads) minScore = std::min(minScore, th->rootMoves[0].score); @@ -287,7 +287,14 @@ void MainThread::search() { votes[th->rootMoves[0].pv[0]] += (th->rootMoves[0].score - minScore + 14) * int(th->completedDepth); - if (votes[th->rootMoves[0].pv[0]] > votes[bestThread->rootMoves[0].pv[0]]) + if (bestThread->rootMoves[0].score >= VALUE_MATE_IN_MAX_PLY) + { + // Make sure we pick the shortest mate + if (th->rootMoves[0].score > bestThread->rootMoves[0].score) + bestThread = th; + } + else if ( th->rootMoves[0].score >= VALUE_MATE_IN_MAX_PLY + || votes[th->rootMoves[0].pv[0]] > votes[bestThread->rootMoves[0].pv[0]]) bestThread = th; } }