From a077d9bd3eb7a89efd3213b84f016ac43f28b48c Mon Sep 17 00:00:00 2001 From: rektdie Date: Fri, 6 Jun 2025 11:45:40 +0200 Subject: [PATCH 1/3] added SE | bench 3280769 --- source/search.cpp | 51 +++++++++++++++++++++++++++++++++++++---------- source/search.h | 2 ++ 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index 642c868..3137491 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -244,10 +244,12 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear int bestScore = NNUE::net.Evaluate(board); ctx->ss[ply].eval = bestScore; - - TTEntry *entry = ctx->TT.GetRawEntry(board.hashKey); - if (entry->hashKey == board.hashKey) { - bestScore = entry->score; + + if (!ctx->excluded) { + TTEntry *entry = ctx->TT.GetRawEntry(board.hashKey); + if (entry->hashKey == board.hashKey) { + bestScore = entry->score; + } } @@ -331,7 +333,10 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (ply && (IsDraw(board, ctx))) return 0; - TTEntry entry = ctx->TT.ReadEntry(board.hashKey, depth, alpha, beta); + TTEntry entry = TTEntry(invalidEntry); + if (!ctx->excluded) + entry = ctx->TT.ReadEntry(board.hashKey, depth, alpha, beta); + const bool ttHit = entry.score != invalidEntry; // if NOT PV node then we try to hit the TTable @@ -357,7 +362,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC return true; }(); - if (!board.InCheck()) { + if (!board.InCheck() && !ctx->excluded) { if (ply) { // Reverse Futility Pruning int margin = 100 * (depth - improving); @@ -374,6 +379,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC const int reduction = 3 + improving; + copy.MakeMove(Move()); + ctx->doingNullMove = true; int score = -PVS(copy, depth - reduction, -beta, -beta + 1, ply + 1, ctx, !cutnode).score; ctx->doingNullMove = false; @@ -401,6 +408,9 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC for (int i = 0; i < board.currentMoveIndex; i++) { Move currMove = board.moveList[i]; + if (ctx->excluded == currMove) + continue; + bool notMated = results.score > (-MATE_SCORE + MAX_PLY); // Late move pruning @@ -428,7 +438,6 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC continue; } - Board copy = board; bool isLegal = copy.MakeMove(currMove); @@ -443,6 +452,26 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC ctx->positionHistory[copy.positionIndex] = copy.hashKey; ctx->nodes++; + int extension = 0; + + if (ply + && depth >= 8 + && currMove == entry.bestMove + && ctx->excluded == 0 + && entry.depth >= depth - 3 + && entry.nodeType != AllNode) + { + const int sBeta = std::max(-inf + 1, entry.score - depth * 2); + const int sDepth = (depth - 1) / 2; + + ctx->excluded = currMove; + const int score = PVS(board, sDepth, sBeta-1, sBeta, ply, ctx, cutnode).score; + ctx->excluded = Move(); + + if (score < sBeta) + extension = 1; + } + // PVS SEE int SEEThreshold = currMove.IsQuiet() ? -80 * depth : -30 * depth * depth; @@ -451,7 +480,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC int reductions = GetReductions(board, currMove, depth, moveSeen, ply, cutnode, ctx); - int newDepth = depth + copy.InCheck() - 1; + int newDepth = depth + copy.InCheck() - 1 + extension; // First move (suspected PV node) if (!moveSeen) { @@ -522,7 +551,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC } } - ctx->TT.WriteEntry(board.hashKey, depth, score, CutNode, currMove); + if (!ctx->excluded) + ctx->TT.WriteEntry(board.hashKey, depth, score, CutNode, currMove); return score; } @@ -545,7 +575,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC } if (ctx->searchStopped) return 0; - ctx->TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); + if (!ctx->excluded) + ctx->TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); return results; } diff --git a/source/search.h b/source/search.h index 3d17c03..cbe0896 100644 --- a/source/search.h +++ b/source/search.h @@ -121,6 +121,8 @@ public: int timeToSearch = 0; int seldepth = 0; + + Move excluded = Move(); bool doingNullMove = false; bool searchStopped = false; -- 2.47.3 From 68377cbf7b24f1b522a3c8edc3e077606042a658 Mon Sep 17 00:00:00 2001 From: rektdie Date: Mon, 28 Jul 2025 23:10:51 +0200 Subject: [PATCH 2/3] added cutnode to SE | bench 1894069 --- source/search.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index 3137491..d78ef1c 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -374,13 +374,10 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (!ctx->doingNullMove && staticEval >= beta) { if (depth > 1 && !board.InPossibleZug()) { Board copy = board; - bool isLegal = copy.MakeMove(Move()); - // Always legal so we dont check it - - const int reduction = 3 + improving; - copy.MakeMove(Move()); + const int reduction = 3 + improving; + ctx->doingNullMove = true; int score = -PVS(copy, depth - reduction, -beta, -beta + 1, ply + 1, ctx, !cutnode).score; ctx->doingNullMove = false; @@ -470,6 +467,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (score < sBeta) extension = 1; + else if (cutnode) + extension = -2; } // PVS SEE -- 2.47.3 From dbeec1b9c62d823482e2876b51d8247e99a8cc1e Mon Sep 17 00:00:00 2001 From: rektdie Date: Mon, 28 Jul 2025 23:37:02 +0200 Subject: [PATCH 3/3] removed cutnode from SE | bench 27398493 --- source/benchmark.h | 2 +- source/search.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/source/benchmark.h b/source/benchmark.h index 9e63d41..3f083f5 100644 --- a/source/benchmark.h +++ b/source/benchmark.h @@ -1,6 +1,6 @@ #pragma once #include -constexpr int BENCH_DEPTH = 11; +constexpr int BENCH_DEPTH = 16; void RunBenchmark(); diff --git a/source/search.cpp b/source/search.cpp index d78ef1c..124448e 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -467,8 +467,6 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC if (score < sBeta) extension = 1; - else if (cutnode) - extension = -2; } // PVS SEE -- 2.47.3