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
+35 -37
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)
reduction += lmrImproving;
if (corrplexity) if (!improving)
reduction -= lmrCorrplexity; reduction += lmrImproving;
if (ttpv) if (corrplexity)
reduction -= lmrTTPV; reduction -= lmrCorrplexity;
if (ttpvFailLow) if (ttpv)
reduction += lmrTTPVFailLow; reduction -= lmrTTPV;
// History LMR if (ttpvFailLow)
int historyReduction = 0; reduction += lmrTTPVFailLow;
if (move.IsQuiet()) { // History LMR
bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom()); int historyReduction = 0;
bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveTo());
historyReduction = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened]; if (move.IsQuiet()) {
if (ply > 0) { bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom());
historyReduction += ctx->conthist.GetNPly(board, move, ctx, ply, 1); bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveTo());
if (ply > 1) historyReduction = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened];
historyReduction += ctx->conthist.GetNPly(board, move, ctx, ply, 2); if (ply > 0) {
} historyReduction += ctx->conthist.GetNPly(board, move, ctx, ply, 1);
} else if (move.IsCapture()) {
int attackerType = board.GetPieceType(move.MoveFrom());
int targetType = board.GetPieceType(move.MoveTo());
if (move.GetFlags() == epCapture) { if (ply > 1)
targetType = Pawn; historyReduction += ctx->conthist.GetNPly(board, move, ctx, ply, 2);
} }
} else if (move.IsCapture()) {
historyReduction = ctx->capthist[board.sideToMove][attackerType][targetType][move.MoveTo()]; int attackerType = board.GetPieceType(move.MoveFrom());
int targetType = board.GetPieceType(move.MoveTo());
if (move.GetFlags() == epCapture) {
targetType = Pawn;
} }
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) {