From ed6b8d179a42414151fa1da69cebe1f2c8cfdd20 Mon Sep 17 00:00:00 2001 From: FauziAkram Date: Mon, 28 Apr 2025 16:46:30 +0300 Subject: [PATCH] Refactor futility_margin a small term to the futility calculation that depends on eval - beta. Passed STC: LLR: 2.95 (-2.94,2.94) <0.00,2.00> Total: 203136 W: 52797 L: 52239 D: 98100 Ptnml(0-2): 549, 23827, 52255, 24391, 546 https://tests.stockfishchess.org/tests/view/680e84a43629b02d74b15e2e Passed LTC: LLR: 2.94 (-2.94,2.94) <0.50,2.50> Total: 100356 W: 25950 L: 25507 D: 48899 Ptnml(0-2): 35, 10683, 28302, 11120, 38 https://tests.stockfishchess.org/tests/view/680ebcb03629b02d74b16040 closes https://github.com/official-stockfish/Stockfish/pull/6009 closes https://github.com/official-stockfish/Stockfish/pull/6041 Bench: 1815939 Co-authored-by: Michael Chaly Co-authored-by: xu-shawn <50402888+xu-shawn@users.noreply.github.com> --- src/search.cpp | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 05d522b19..870cff54b 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -70,23 +70,6 @@ namespace { // so changing them or adding conditions that are similar requires // tests at these types of time controls. -// Futility margin -Value futility_margin(Depth d, - bool noTtCutNode, - bool improving, - bool oppWorsening, - int statScore, - int correctionValue) { - Value futilityMult = 105 - 23 * noTtCutNode; - Value improvingDeduction = improving * futilityMult * 2; - Value worseningDeduction = oppWorsening * futilityMult / 3; - Value statScoreAddition = statScore / 335; - Value correctionAddition = correctionValue / 149902; - - return futilityMult * d - improvingDeduction - worseningDeduction + statScoreAddition - + correctionAddition; -} - constexpr int futility_move_count(bool improving, Depth depth) { return (3 + depth * depth) / (2 - improving); } @@ -864,13 +847,23 @@ Value Search::Worker::search( // Step 8. Futility pruning: child node // The depth condition is important for mate finding. - if (!ss->ttPv && depth < 14 - && eval - - futility_margin(depth, cutNode && !ss->ttHit, improving, opponentWorsening, - (ss - 1)->statScore, std::abs(correctionValue)) - >= beta - && eval >= beta && (!ttData.move || ttCapture) && !is_loss(beta) && !is_win(eval)) - return beta + (eval - beta) / 3; + { + auto futility_margin = [&](Depth d) { + Value futilityMult = 105 - 23 * (cutNode && !ss->ttHit); + Value improvingDeduction = improving * futilityMult * 2; + Value worseningDeduction = opponentWorsening * futilityMult / 3; + + return futilityMult * d // + - improvingDeduction // + - worseningDeduction // + + (ss - 1)->statScore / 335 // + + std::abs(correctionValue) / 149902; + }; + + if (!ss->ttPv && depth < 14 && eval + (eval - beta) / 8 - futility_margin(depth) >= beta + && eval >= beta && (!ttData.move || ttCapture) && !is_loss(beta) && !is_win(eval)) + return beta + (eval - beta) / 3; + } // Step 9. Null move search with verification search if (cutNode && (ss - 1)->currentMove != Move::null() && eval >= beta