fixed both PVS and QS

This commit is contained in:
rektdie committed 2025-03-09 04:39:11 +01:00
1 parent 02b28b2598
commit 28bec280cc
1 file changed
+9 -10
+9 -10
View File
@@ -97,13 +97,12 @@ static SearchResults Quiescence(Board board, int alpha, int beta) {
nodes++; nodes++;
int staticScore = Evaluate(board); int staticScore = Evaluate(board);
int bestScore = alpha;
if (staticScore >= beta) { if (staticScore >= beta) {
return staticScore; return staticScore;
} }
int bestScore = alpha;
if (staticScore > bestScore) { if (staticScore > bestScore) {
bestScore = staticScore; bestScore = staticScore;
} }
@@ -118,7 +117,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta) {
if (board.moveList[i].IsCapture()) { if (board.moveList[i].IsCapture()) {
Board copy = board; Board copy = board;
copy.MakeMove(board.moveList[i]); copy.MakeMove(board.moveList[i]);
int score = -Quiescence(copy, -beta, -alpha).score; int score = -Quiescence(copy, -beta, -bestScore).score;
if (score >= beta) { if (score >= beta) {
return score; 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); if (depth <= 0) return Quiescence(board, alpha, beta);
const int staticEval = Evaluate(board);
if (board.InCheck(board.sideToMove)) { if (board.InCheck(board.sideToMove)) {
depth++; depth++;
} else { } else {
@@ -204,8 +203,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) {
} }
} }
int bestScore = alpha; SearchResults results(-inf);
SearchResults results;
// For all moves // For all moves
for (int i = 0; i < board.currentMoveIndex; i++) { for (int i = 0; i < board.currentMoveIndex; i++) {
@@ -241,14 +239,15 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) {
return score; return score;
} }
if (score > bestScore) { results.score = std::max(score, results.score);
if (score > alpha) {
nodeType = PV; nodeType = PV;
bestScore = score; alpha = score;
results.bestMove = board.moveList[i]; results.bestMove = board.moveList[i];
} }
} }
results.score = bestScore;
WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
if (searchStopped) return 0; if (searchStopped) return 0;
return results; return results;