Lmr #23

Merged
rektdie merged 2 commits from LMR into main 2025-03-18 22:58:49 +01:00
Showing only changes of commit b3e0bb9a03 - Show all commits
+27 -6
View File
@@ -95,6 +95,17 @@ static bool IsThreefold(Board &board) {
return false; 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) { static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
if (!benchStarted) { if (!benchStarted) {
if (sw.GetElapsedMS() >= timeToSearch) { if (sw.GetElapsedMS() >= timeToSearch) {
@@ -218,18 +229,28 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
Board copy = board; Board copy = board;
copy.MakeMove(currMove); copy.MakeMove(currMove);
int reductions = GetReductions(board, depth, i);
// First move (suspected PV node) // First move (suspected PV node)
if (!i) { if (!i) {
// Full search // Full search
score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score; score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score;
} else { } else if (reductions) {
// Quick search // Null-window search with reductions
score = -PVS(copy, depth - 1, -alpha-1, -alpha, ply + 1).score; score = -PVS(copy, depth - 1 - reductions, -alpha-1, -alpha, ply + 1).score;
if (score > alpha && beta - alpha > 1) { if (score > alpha) {
// We have to do full search // Null-window search now without the reduction
score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score; 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--; positionIndex--;