diff --git a/source/search.cpp b/source/search.cpp index fea8128..0ee8e1e 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -399,7 +399,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC } // Null Move Pruning - if (!ctx->doingNullMove && staticEval >= beta + nmpBetaMargin) { + if (ply > ctx->minNmpPly && staticEval >= beta + nmpBetaMargin) { if (depth > 1 && !board.InPossibleZug()) { Board copy = board; copy.MakeMove(Move()); @@ -408,12 +408,24 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC ctx->TT.PrefetchEntry(copy.hashKey); - ctx->doingNullMove = true; int score = -PVS(copy, depth - reduction, -beta, -beta + 1, ply + 1, ctx, !cutnode).score; - ctx->doingNullMove = false; if (ctx->searchStopped) return 0; - if (score >= beta) return score; + if (score >= beta) { + if (depth <= 14 || ctx->minNmpPly > 0) { + return score > MATE_SCORE - MAX_DEPTH ? beta : score; + } + + ctx->minNmpPly = ply + (depth - reduction) * 3 / 4; + + const auto verifResults = PVS(copy, depth - reduction, beta - 1, beta, ply + 1, ctx, true); + + ctx->minNmpPly = 0; + + if (verifResults.score >= beta) { + return verifResults; + } + } } } } diff --git a/source/search.h b/source/search.h index 638bb42..6592d95 100644 --- a/source/search.h +++ b/source/search.h @@ -217,7 +217,7 @@ public: Move excluded = Move(); - bool doingNullMove = false; + int minNmpPly = 0; bool searchStopped = false; PVLine pvLine;