From 732ad08f0102b4da81553ecae01a07e279db966b Mon Sep 17 00:00:00 2001 From: rektdie Date: Fri, 21 Mar 2025 11:05:13 +0100 Subject: [PATCH] template for PVS | bench 991332 --- source/benchmark.cpp | 2 +- source/search.cpp | 19 ++++++++++--------- source/search.h | 4 +++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/source/benchmark.cpp b/source/benchmark.cpp index 02528e5..a4e9f29 100644 --- a/source/benchmark.cpp +++ b/source/benchmark.cpp @@ -80,7 +80,7 @@ void RunBenchmark() { Stopwatch sw; for (int i = 0; i < fenPositions.size(); i++) { board.SetByFen(fenPositions[i]); - PVS(board, depth, -inf, inf, ply); + PVS(board, depth, -inf, inf, ply); } std::cout << nodes << " nodes " << int(nodes/sw.GetElapsedSec()) << " nps\n"; diff --git a/source/search.cpp b/source/search.cpp index 6874efe..3ea3af0 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -161,6 +161,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply) { return results; } +template SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { if (!benchStarted) { if (sw.GetElapsedMS() >= timeToSearch) { @@ -174,7 +175,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { // if NOT PV node then we try to hit the TTable - if (beta - alpha == 1) { + if constexpr (!isPV) { SearchResults entry = TT.ReadEntry(board.hashKey, depth, alpha, beta); if (entry.score != invalidEntry) { return entry; @@ -202,7 +203,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { copy.MakeMove(Move()); doingNullMove = true; - int score = -PVS(copy, depth - 3, -beta, -beta + 1, ply + 1).score; + int score = -PVS(copy, depth - 3, -beta, -beta + 1, ply + 1).score; doingNullMove = false; if (searchStopped) return 0; @@ -240,23 +241,23 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { // First move (suspected PV node) if (!i) { // Full search - score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score; + score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score; } else if (reductions) { // Null-window search with reductions - score = -PVS(copy, depth - 1 - reductions, -alpha-1, -alpha, ply + 1).score; + score = -PVS(copy, depth - 1 - reductions, -alpha-1, -alpha, ply + 1).score; if (score > alpha) { // Null-window search now without the reduction - score = -PVS(copy, depth - 1, -alpha-1, -alpha, ply + 1).score; + score = -PVS(copy, depth - 1, -alpha-1, -alpha, ply + 1).score; } } else { // Null-window search - score = -PVS(copy, depth - 1, -alpha-1, -alpha, ply + 1).score; + score = -PVS(copy, depth - 1, -alpha-1, -alpha, ply + 1).score; } // Check if we need to do full window re-search if (i && score > alpha && score < beta) { - score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score; + score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score; } positionIndex--; @@ -309,7 +310,7 @@ static SearchResults ID(Board &board, SearchParams params) { for (int depth = 1; depth <= 99; depth++) { timeToSearch = (fullTime / 20) + (inc / 2); - SearchResults currentResults = PVS(board, depth, alpha, beta, ply); + SearchResults currentResults = PVS(board, depth, alpha, beta, ply); // If we fell outside the window, try again with full width if ((currentResults.score <= alpha) @@ -363,4 +364,4 @@ void SearchPosition(Board &board, SearchParams params) { void StopSearch() { searchStopped = true; } -} \ No newline at end of file +} diff --git a/source/search.h b/source/search.h index 1458400..0e92068 100644 --- a/source/search.h +++ b/source/search.h @@ -96,7 +96,9 @@ public: } }; +template SearchResults PVS(Board board, int depth, int alpha, int beta, int ply); + void SearchPosition(Board &board, SearchParams params); void StopSearch(); @@ -110,4 +112,4 @@ constexpr int moveScoreTable[6][6] = { }; void ListScores(Board &board); -} \ No newline at end of file +}