From 48b40ec9ff5f502eae4a384fcf554e34583c9c12 Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 23 Oct 2025 00:54:34 +0200 Subject: [PATCH] lmr rework | bench 4645054 --- source/search.cpp | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index d8aa55e..c4c674d 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -167,37 +167,39 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int int reduction = 0; // Late Move Reduction - if (depth >= 2 && moveSeen >= 2 + (2 * isPV) && !move.IsCapture()) { + if (depth >= 2 && moveSeen >= 2 + (2 * isPV)) { reduction = lmrTable[move.IsQuiet()][depth][moveSeen] * 1024; if (cutnode) - reduction += lmrCutnode; + reduction += lmrCutnode; - if constexpr (isPV) - reduction -= lmrIsPV; - - if (!improving) - reduction += lmrImproving; + if (!move.IsCapture()) { + if constexpr (isPV) + reduction -= lmrIsPV; + + if (!improving) + reduction += lmrImproving; - bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom()); - bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveTo()); + bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom()); + bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveTo()); - // History LMR - int historyReduction = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened]; - if (ply > 0) { - historyReduction += ctx->conthist.GetOnePly(board, move, ctx, ply); + // History LMR + int historyReduction = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened]; + if (ply > 0) { + historyReduction += ctx->conthist.GetOnePly(board, move, ctx, ply); - if (ply > 1) - historyReduction += ctx->conthist.GetTwoPly(board, move, ctx, ply); + if (ply > 1) + historyReduction += ctx->conthist.GetTwoPly(board, move, ctx, ply); + } + + historyReduction = historyReduction / lmrHistoryDivisor; + + reduction -= historyReduction * 1024; } - - reduction /= 1024; - - historyReduction = historyReduction / lmrHistoryDivisor; - - reduction -= historyReduction; } + reduction /= 1024; + return std::clamp(reduction, -1, depth - 1); }