[Board] Implement enPassant move handling

This commit is contained in:
2022-12-21 20:03:59 +01:00
parent c52f57293e
commit 4671fec523
2 changed files with 14 additions and 1 deletions

View File

@@ -108,13 +108,25 @@ void Board::makeMove(const Move &move) {
}
}
// en passant
handleEnPassant(move, movedPiece);
handlePawnDoubleAdvance(move, toBB, movedPiece);
// change turn
mTurn = !mTurn;
}
void Board::handleEnPassant(const Move &move, const Piece &movedPiece) {
if (movedPiece.type() == PieceType::Pawn && mEPS.has_value() && move.from().file() != move.to().file()) {
auto epBB = indexToBitBoard(Square::fromCoordinates(move.to().file(), move.from().rank())->index());
auto capturedPiece = Piece(!mTurn, PieceType::Pawn);
mPieceBBs[toIndex(capturedPiece.color())] ^= epBB;
mPieceBBs[toIndex(capturedPiece.type())] ^= epBB;
mOccupiedBB ^= epBB;
}
}
void Board::handlePawnDoubleAdvance(const Move &move, BitBoard bb, const Piece &movedPiece) {
if (movedPiece.type() == PieceType::Pawn) {
auto fromR = move.from().rank();

View File

@@ -128,6 +128,7 @@ private:
}
void handlePawnDoubleAdvance(const Move &move, BitBoard bb, const Piece &movedPiece);
void handleEnPassant(const Move &move, const Piece &movedPiece);
};
std::ostream &operator<<(std::ostream &os, const Board &board);