Pvs rewrite #171

Merged
rektdie merged 7 commits from pvs-rewrite into main 2026-03-28 04:18:23 +01:00
Showing only changes of commit 081d54dc55 - Show all commits
+34 -36
View File
@@ -98,56 +98,54 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int
int reduction = 0; int reduction = 0;
// Late Move Reduction // Late Move Reduction
if (depth >= 2 && moveSeen >= 2 + (2 * isPV)) { reduction = lmrTable[move.IsQuiet()][depth][moveSeen] * 1024;
reduction = lmrTable[move.IsQuiet()][depth][moveSeen] * 1024;
if (cutnode) if (cutnode)
reduction += lmrCutnode; reduction += lmrCutnode;
if constexpr (isPV) if constexpr (isPV)
reduction -= lmrIsPV; reduction -= lmrIsPV;
if (!improving) if (!improving)
reduction += lmrImproving; reduction += lmrImproving;
if (corrplexity) if (corrplexity)
reduction -= lmrCorrplexity; reduction -= lmrCorrplexity;
if (ttpv) if (ttpv)
reduction -= lmrTTPV; reduction -= lmrTTPV;
if (ttpvFailLow) if (ttpvFailLow)
reduction += lmrTTPVFailLow; reduction += lmrTTPVFailLow;
// History LMR // History LMR
int historyReduction = 0; int historyReduction = 0;
if (move.IsQuiet()) { if (move.IsQuiet()) {
bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom()); bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom());
bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveTo()); bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveTo());
historyReduction = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened]; historyReduction = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened];
if (ply > 0) { if (ply > 0) {
historyReduction += ctx->conthist.GetNPly(board, move, ctx, ply, 1); historyReduction += ctx->conthist.GetNPly(board, move, ctx, ply, 1);
if (ply > 1) if (ply > 1)
historyReduction += ctx->conthist.GetNPly(board, move, ctx, ply, 2); historyReduction += ctx->conthist.GetNPly(board, move, ctx, ply, 2);
} }
} else if (move.IsCapture()) { } else if (move.IsCapture()) {
int attackerType = board.GetPieceType(move.MoveFrom()); int attackerType = board.GetPieceType(move.MoveFrom());
int targetType = board.GetPieceType(move.MoveTo()); int targetType = board.GetPieceType(move.MoveTo());
if (move.GetFlags() == epCapture) { if (move.GetFlags() == epCapture) {
targetType = Pawn; targetType = Pawn;
}
historyReduction = ctx->capthist[board.sideToMove][attackerType][targetType][move.MoveTo()];
} }
historyReduction = historyReduction / lmrHistoryDivisor; historyReduction = ctx->capthist[board.sideToMove][attackerType][targetType][move.MoveTo()];
reduction -= historyReduction * 1024;
} }
historyReduction = historyReduction / lmrHistoryDivisor;
reduction -= historyReduction * 1024;
reduction /= 1024; reduction /= 1024;
return std::clamp(reduction, -1, depth - 1); return std::clamp(reduction, -1, depth - 1);
@@ -668,7 +666,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
U64 nodesBeforeSearch = ctx->nodes; U64 nodesBeforeSearch = ctx->nodes;
if (reductions > 0) { if (depth >= 2 && moveSeen >= 2 + (2 * isPV)) {
score = -PVS<false, mode>(copy, reduced, -alpha - 1, -alpha, ply + 1, ctx, true).score; score = -PVS<false, mode>(copy, reduced, -alpha - 1, -alpha, ply + 1, ctx, true).score;
if (score > alpha && reduced < newDepth) { if (score > alpha && reduced < newDepth) {