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

+9 -12
View File
@@ -159,20 +159,14 @@ int Board::GetPieceColor(int square) {
}
bool Board::InCheck() {
int kingSquare = (pieces[King] & colors[sideToMove]).getLS1BIndex();
Bitboard myKingSquare = colors[sideToMove] & pieces[King];
for (int type = Pawn; type <= Queen; type++) {
Bitboard moves = MOVEGEN::getPieceAttacks(kingSquare, type, sideToMove, occupied);
if (moves & colors[!sideToMove] & pieces[type]) return true;
}
return false;
return GetThreatMaps(!sideToMove) & myKingSquare;
}
bool Board::IsLegal(Move move) {
Board copy = *this;
copy.MakeMove(move);
copy.MakeMove(move, true);
copy.sideToMove = sideToMove;
positionIndex--;
@@ -231,9 +225,10 @@ void Board::Promote(int square, int pieceType, int color, bool isCapture) {
SetPiece(pieceType, square, color);
}
void Board::MakeMove(Move move) {
SEARCH::nodes++;
void Board::MakeMove(Move move, bool legalityCheck) {
if (!legalityCheck) {
SEARCH::nodes++;
}
// Null Move
if (!move) {
int newEpTarget = noEPTarget;
@@ -357,6 +352,8 @@ void Board::MakeMove(Move move) {
positionIndex++;
positionHistory[positionIndex] = hashKey;
MOVEGEN::GenThreatMaps(*this);
}
bool Board::InPossibleZug() {