From 7b37032885b20d95472ef08fd38bad16f07ada25 Mon Sep 17 00:00:00 2001 From: "Robert Nurnberg @ elitebook" <28635489+robertnurnberg@users.noreply.github.com> Date: Wed, 10 Jun 2026 12:42:01 +0200 Subject: [PATCH] Stop searching if we cannot find a better move In a recent CCC event, Stockfish (probably through no fault of its own), lost some games on time when it was winning and when it had already found the move that delivers checkmate. This patch stops the search when TM is active, and when mainthread can be certain that it is impossible to find a better move. That is if (i) it has found mate-in-1, (ii) it has found a mate-in-2 or (iii) it has found a mated-in-1. patch: ``` position fen 5K2/8/2qk4/2nPp3/3r4/6B1/B7/3R4 w - e6 go wtime 100000000 winc 100000000 info string Available processors: 0-7 info string Using 1 thread info string NNUE evaluation using nn-71d6d32cb962.nnue (106MiB, (83248, 1024, 31, 32, 1)) info string Network replica 1: Shared memory. info depth 1 seldepth 3 multipv 1 score mate 1 nodes 30 nps 30000 hashfull 0 tbhits 0 time 1 pv d5e6 bestmove d5e6 ``` master: ``` position fen 5K2/8/2qk4/2nPp3/3r4/6B1/B7/3R4 w - e6 go wtime 100000000 winc 100000000 info string Available processors: 0-7 info string Using 1 thread info string NNUE evaluation using nn-71d6d32cb962.nnue (106MiB, (83248, 1024, 31, 32, 1)) info string Network replica 1: Shared memory. info depth 1 seldepth 3 multipv 1 score mate 1 nodes 30 nps 15000 hashfull 0 tbhits 0 time 2 pv d5e6 info depth 245 seldepth 2 multipv 1 score mate 1 nodes 5886 nps 367875 hashfull 0 tbhits 0 time 16 pv d5e6 bestmove d5e6 ``` Note: In MultiPV analysis (extremely rare with TM active), we take the point of view that the user would like to continue to search until none of the PVs can be improved anymore. This means we only stop if the worst searched line is at least a mate-in-2, or if the best searched line is a mated-in-1. closes https://github.com/official-stockfish/Stockfish/pull/6879 No functional change --- src/search.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 6d05d2c8a..b497552ae 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -583,8 +583,10 @@ bool Search::Worker::iterative_deepening() { auto elapsedTime = elapsed(); - // Stop the search if we have exceeded the totalTime or maximum - if (elapsedTime > std::min(totalTime, double(mainThread->tm.maximum()))) + // Stop the search if we have exceeded totalTime or maximum time, + // or if we know that there are no better moves in the analysed line(s) + if (elapsedTime > std::min(totalTime, double(mainThread->tm.maximum())) + || rootMoves[multiPV - 1].score >= mate_in(3) || rootMoves[0].score == mated_in(2)) { // If we are allowed to ponder do not stop the search now but // keep pondering until the GUI sends "ponderhit" or "stop".