From 28bec280cc9a35adaf2946caa61dcb456e904543 Mon Sep 17 00:00:00 2001 From: rektdie Date: Sun, 9 Mar 2025 04:39:11 +0100 Subject: [PATCH] fixed both PVS and QS --- source/search.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index af127f0..cca5501 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -97,13 +97,12 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { nodes++; int staticScore = Evaluate(board); + int bestScore = alpha; if (staticScore >= beta) { return staticScore; } - int bestScore = alpha; - if (staticScore > bestScore) { bestScore = staticScore; } @@ -118,7 +117,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta) { if (board.moveList[i].IsCapture()) { Board copy = board; copy.MakeMove(board.moveList[i]); - int score = -Quiescence(copy, -beta, -alpha).score; + int score = -Quiescence(copy, -beta, -bestScore).score; if (score >= beta) { return score; @@ -155,10 +154,10 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { } } - const int staticEval = Evaluate(board); - if (depth <= 0) return Quiescence(board, alpha, beta); + const int staticEval = Evaluate(board); + if (board.InCheck(board.sideToMove)) { depth++; } else { @@ -204,8 +203,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { } } - int bestScore = alpha; - SearchResults results; + SearchResults results(-inf); // For all moves for (int i = 0; i < board.currentMoveIndex; i++) { @@ -241,14 +239,15 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { return score; } - if (score > bestScore) { + results.score = std::max(score, results.score); + + if (score > alpha) { nodeType = PV; - bestScore = score; + alpha = score; results.bestMove = board.moveList[i]; } } - results.score = bestScore; WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); if (searchStopped) return 0; return results; @@ -331,4 +330,4 @@ void SearchPosition(Board &board, SearchParams params) { void StopSearch() { searchStopped = true; -} +} \ No newline at end of file