fixed checkmate and stalemate detection

This commit is contained in:
rektdie committed 2025-03-24 20:01:32 +01:00
1 parent 3090dbac8b
commit d4c7263b93
5 files changed
+24 -27

No files matched your search

+11 -11
View File
@@ -140,7 +140,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
if (!board.IsLegal(board.moveList[i])) continue;
if (board.moveList[i].IsCapture()) {
Board copy = board;
copy.MakeMove(board.moveList[i]);
copy.MakeMove(board.moveList[i], false);
int score = -Quiescence(copy, -beta, -alpha, ply + 1).score;
positionIndex--;
@@ -201,7 +201,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
if (!doingNullMove && staticEval >= beta) {
if (depth >= 3 && !board.InPossibleZug()) {
Board copy = board;
copy.MakeMove(Move());
copy.MakeMove(Move(), false);
doingNullMove = true;
int score = -PVS<false>(copy, depth - 3, -beta, -beta + 1, ply + 1).score;
@@ -216,14 +216,6 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
MOVEGEN::GenerateMoves<All>(board);
if (board.currentMoveIndex == 0) {
if (board.InCheck()) { // checkmate
return -99000 + ply;
} else { // stalemate
return 0;
}
}
SortMoves(board, ply);
int score = -inf;
@@ -239,7 +231,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
if (!board.IsLegal(currMove)) continue;
Board copy = board;
copy.MakeMove(currMove);
copy.MakeMove(currMove, false);
int reductions = GetReductions(board, currMove, depth, moveSeen, ply);
@@ -291,6 +283,14 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
}
}
if (moveSeen == 0) {
if (board.InCheck()) { // checkmate
return -99000 + ply;
} else { // stalemate
return 0;
}
}
TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
if (searchStopped) return 0;
return results;