feat: en passant generally implemented

This commit is contained in:
A.M. Rowsell 2026-09-22 01:58:46 -04:00
commit 10a4dcb60b
Signed by: amr
GPG key ID: E0879EDBDB0CA7B1
4 changed files with 53 additions and 12 deletions

View file

@ -288,7 +288,29 @@ void Board::nextTurn() {
}
void Board::movePiece(Square from, Square to) {
return;
Piece *movingPiece = getPieceAt(from);
if(!movingPiece) return;
Square newEnPassantTarget = {INVALID_RANK, INVALID_FILE};
if(movingPiece->getPieceType() == PAWN) {
// Check if it's a 2-square move
if(abs(to.rank - from.rank) == 2) {
int dir = (to.rank > from.rank) ? -1 : 1;
newEnPassantTarget = {static_cast<Rank>(to.rank + dir), from.file};
}
// Check if it's an en passant capture (diagonal move to an empty square)
else if(to.file != from.file && isSquareEmpty(to)) {
// The captured pawn is on the same rank as 'from', but the file of 'to'
clearSquare(from.rank, to.file);
}
}
// Move the piece
setPieceAt(to, std::move(boardGrid[from.rank][from.file]));
clearSquare(from);
enPassantTargetSquare = newEnPassantTarget;
}
void Board::deserializeBoard(uint64_t incomingBoard) {