From b3e0bb9a03a8fd859afff1f0417d35972a9656ab Mon Sep 17 00:00:00 2001 From: rektdie Date: Tue, 18 Mar 2025 20:10:35 +0100 Subject: [PATCH] added LMR with basic formula | bench 768742 --- source/search.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index 3803656..eedb753 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -95,6 +95,17 @@ static bool IsThreefold(Board &board) { return false; } +static int GetReductions(Board &board, int depth, int moveSeen) { + int reduction = 0; + + // Late Move Reduction + if (!board.InCheck(board.sideToMove) && moveSeen >= 5 && depth > 3) { + reduction++; + } + + return reduction; +} + static SearchResults Quiescence(Board board, int alpha, int beta, int ply) { if (!benchStarted) { if (sw.GetElapsedMS() >= timeToSearch) { @@ -218,18 +229,28 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { Board copy = board; copy.MakeMove(currMove); + int reductions = GetReductions(board, depth, i); + // First move (suspected PV node) if (!i) { // Full search score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score; - } else { - // Quick search - score = -PVS(copy, depth - 1, -alpha-1, -alpha, ply + 1).score; + } else if (reductions) { + // Null-window search with reductions + score = -PVS(copy, depth - 1 - reductions, -alpha-1, -alpha, ply + 1).score; - if (score > alpha && beta - alpha > 1) { - // We have to do full search - score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score; + if (score > alpha) { + // Null-window search now without the reduction + score = -PVS(copy, depth - 1, -alpha-1, -alpha, ply + 1).score; } + } else { + // Null-window search + score = -PVS(copy, depth - 1, -alpha-1, -alpha, ply + 1).score; + } + + // Check if we need to do full window re-search + if (i && score > alpha && score < beta) { + score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score; } positionIndex--;