feat: en passant generally implemented
This commit is contained in:
parent
1842e25918
commit
10a4dcb60b
4 changed files with 53 additions and 12 deletions
24
Board.cpp
24
Board.cpp
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue