diff --git a/source/search.cpp b/source/search.cpp index 4bb4c1f..c7aec82 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -664,32 +664,26 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC int reductions = GetReductions(board, currMove, depth, moveSeen, ply, cutnode, improving, corrplexity, ttpv, ttpvFailLow, ctx); int newDepth = depth + (copy.InCheck() && !ctx->excluded) - 1 + extension; + int reduced = newDepth - reductions; U64 nodesBeforeSearch = ctx->nodes; - // First move (suspected PV node) - if (!moveSeen) { - // Full search - if constexpr (isPV) { - score = -PVS(copy, newDepth, -beta, -alpha, ply + 1, ctx, false).score; - } else { - score = -PVS(copy, newDepth, -beta, -alpha, ply + 1, ctx, !cutnode).score; - } - } else if (reductions) { - // Null-window search with reductions - score = -PVS(copy, newDepth - reductions, -alpha-1, -alpha, ply + 1, ctx, true).score; + if (reductions > 0) { + score = -PVS(copy, reduced, -alpha - 1, -alpha, ply + 1, ctx, true).score; - if (score > alpha) { - // Null-window search now without the reduction - score = -PVS(copy, newDepth, -alpha-1, -alpha, ply + 1, ctx, !cutnode).score; + if (score > alpha && reduced < newDepth) { + const bool goDeeper = score > results.score + lmrDeeperBase + lmrDeeperScalar * newDepth; + const bool goShallower = score < results.score + newDepth; + + newDepth += goDeeper - goShallower; + + score = -PVS(copy, newDepth, -alpha - 1, -alpha, ply + 1, ctx, !cutnode).score; } - } else { - // Null-window search - score = -PVS(copy, newDepth, -alpha-1, -alpha, ply + 1, ctx, !cutnode).score; + } else if (!isPV || moveSeen > 1) { + score = -PVS(copy, newDepth, -alpha - 1, -alpha, ply + 1, ctx, !cutnode).score; } - // Check if we need to do full window re-search - if (moveSeen && score > alpha && score < beta) { + if (isPV && (moveSeen == 0 || score > alpha)) { score = -PVS(copy, newDepth, -beta, -alpha, ply + 1, ctx, false).score; } diff --git a/source/tunables.h b/source/tunables.h index 8abb700..ac0a1c0 100644 --- a/source/tunables.h +++ b/source/tunables.h @@ -17,6 +17,8 @@ X_INT(lmrImproving, 1024, 6000, 10000) \ X_INT(lmrCorrplexity, 1024, 6000, 10000) \ X_INT(lmrTTPVFailLow, 1024, 6000, 10000) \ + X_INT(lmrDeeperBase, 30, 6000, 10000) \ + X_INT(lmrDeeperScalar, 4, 6000, 10000) \ X_INT(rfpBase, 25, 50, 200) \ X_INT(rfpMargin, 100, 50, 200) \ X_INT(fpMargin, 100, 50, 200) \