diff --git a/Board.cpp b/Board.cpp index 6fc1746..2d5ad38 100644 --- a/Board.cpp +++ b/Board.cpp @@ -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(); diff --git a/Board.hpp b/Board.hpp index 879d6e6..c35b690 100644 --- a/Board.hpp +++ b/Board.hpp @@ -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);