From 559942d64de9497c9d6d13b22307b4b9e1ce8ecf Mon Sep 17 00:00:00 2001 From: Joost VandeVondele Date: Wed, 9 Jun 2021 23:23:13 +0200 Subject: [PATCH] Limit double extensions Double extensions can lead to search explosions, for specific positions. Currently, however, these double extensions are worth about 10Elo and cannot be removed. This patch instead limits the number of double extensions given to a maximum of 3. This fixes https://github.com/official-stockfish/Stockfish/issues/3532 where the following testcase was shown to be problematic: ``` uci setoption name Hash value 4 setoption name Contempt value 0 ucinewgame position fen 8/Pk6/8/1p6/8/P1K5/8/6B1 w - - 37 130 go depth 20 ``` passed STC: https://tests.stockfishchess.org/tests/view/60c13161457376eb8bcaaa0f LLR: 2.95 (-2.94,2.94) <-2.50,0.50> Total: 73256 W: 6114 L: 6062 D: 61080 Ptnml(0-2): 222, 4912, 26306, 4968, 220 passed LTC: https://tests.stockfishchess.org/tests/view/60c196fb457376eb8bcaaa6b LLR: 2.94 (-2.94,2.94) <-2.50,0.50> Total: 166440 W: 5559 L: 5594 D: 155287 Ptnml(0-2): 106, 4921, 73197, 4894, 102 closes https://github.com/official-stockfish/Stockfish/pull/3544 Bench: 5067605 --- src/search.cpp | 14 ++++++++++---- src/search.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 5306bb9a..d04898e8 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -610,10 +610,11 @@ namespace { assert(0 <= ss->ply && ss->ply < MAX_PLY); - (ss+1)->ttPv = false; + (ss+1)->ttPv = false; (ss+1)->excludedMove = bestMove = MOVE_NONE; - (ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE; - Square prevSq = to_sq((ss-1)->currentMove); + (ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE; + ss->doubleExtensions = (ss-1)->doubleExtensions; + Square prevSq = to_sq((ss-1)->currentMove); // Initialize statScore to zero for the grandchildren of the current position. // So statScore is shared between all grandchildren and only the first grandchild @@ -1074,7 +1075,11 @@ moves_loop: // When in check, search starts from here { extension = 1; singularQuietLMR = !ttCapture; - if (!PvNode && value < singularBeta - 93) + + // Avoid search explosion by limiting the number of double extensions to at most 3 + if ( !PvNode + && value < singularBeta - 93 + && ss->doubleExtensions < 3) extension = 2; } @@ -1105,6 +1110,7 @@ moves_loop: // When in check, search starts from here // Add extension to new depth newDepth += extension; + ss->doubleExtensions = (ss-1)->doubleExtensions + (extension == 2); // Speculative prefetch as early as possible prefetch(TT.first_entry(pos.key_after(move))); diff --git a/src/search.h b/src/search.h index 811b2e2a..801baacc 100644 --- a/src/search.h +++ b/src/search.h @@ -52,6 +52,7 @@ struct Stack { bool inCheck; bool ttPv; bool ttHit; + int doubleExtensions; }; -- 2.39.2