fixed a bug in previous commit + doublePawnPushes were not working
This commit is contained in:
1 parent
e4ca91d565
commit
c97c3acb27
3 files changed
+27
-10
No files matched your search
+16
-7
@@ -291,10 +291,25 @@ void Board::RemovePiece(int piece, int square, bool color) {
|
||||
occupied.PopBit(square);
|
||||
}
|
||||
|
||||
// Updates castling rights on capturing (only if needed)
|
||||
static void UpdateCastlingRights(Board &board, int targetPiece, int targetSquare, int attackerColor) {
|
||||
if (targetPiece == Rook) {
|
||||
int queenSideRook = attackerColor ? a1 : a8;
|
||||
int kingSideRook = attackerColor ? a8 : h8;
|
||||
|
||||
if (targetSquare == queenSideRook) {
|
||||
board.castlingRights[!attackerColor * 2 + 1] = false;
|
||||
} else if (targetSquare == kingSideRook) {
|
||||
board.castlingRights[!attackerColor * 2] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Board::Promote(int square, int pieceType, int color, bool isCapture) {
|
||||
if (isCapture) {
|
||||
int targetType = GetPieceType(square);
|
||||
RemovePiece(targetType, square, !color);
|
||||
UpdateCastlingRights(*this, targetType, square, color);
|
||||
}
|
||||
|
||||
SetPiece(pieceType, square, color);
|
||||
@@ -322,13 +337,7 @@ void Board::MakeMove(Move move) {
|
||||
case capture:
|
||||
RemovePiece(targetPiece, move.MoveTo(), !attackerColor);
|
||||
SetPiece(attackerPiece, move.MoveTo(), attackerColor);
|
||||
|
||||
if (targetPiece == Rook) {
|
||||
int queenSide = move.MoveTo() % 8 == 0;
|
||||
|
||||
castlingRights[!attackerColor * 2 + queenSide] = false;
|
||||
}
|
||||
|
||||
UpdateCastlingRights(*this, targetPiece, move.MoveTo(), attackerColor);
|
||||
break;
|
||||
case epCapture:
|
||||
RemovePiece(Pawn, move.MoveTo() - direction, !attackerColor);
|
||||
|
||||
Reference in new issue
Block a user