[Board] Implement EnPassant handling
This commit is contained in:
20
Board.cpp
20
Board.cpp
@@ -53,11 +53,11 @@ CastlingRights Board::castlingRights() const {
|
||||
void Board::setEnPassantSquare(const Square::Optional &square) {
|
||||
if (!square.has_value())
|
||||
return;
|
||||
mEPS = square->index();
|
||||
mEPS = square;
|
||||
}
|
||||
|
||||
Square::Optional Board::enPassantSquare() const {
|
||||
return Square::fromIndex(mEPS);
|
||||
return mEPS;
|
||||
}
|
||||
|
||||
void Board::makeMove(const Move &move) {
|
||||
@@ -108,10 +108,26 @@ void Board::makeMove(const Move &move) {
|
||||
}
|
||||
}
|
||||
|
||||
// en passant
|
||||
handlePawnDoubleAdvance(move, toBB, movedPiece);
|
||||
|
||||
|
||||
// change turn
|
||||
mTurn = !mTurn;
|
||||
}
|
||||
void Board::handlePawnDoubleAdvance(const Move &move, BitBoard bb, const Piece &movedPiece) {
|
||||
if (movedPiece.type() == PieceType::Pawn) {
|
||||
auto fromR = move.from().rank();
|
||||
auto toR = move.to().rank();
|
||||
auto diff = abs(static_cast<int>(fromR) - static_cast<int>(toR));
|
||||
if (diff == 2 && (mPieceBBs[toIndex(PieceType::Pawn)] & (bb << 1 | bb >> 1) & getRankBB(static_cast<int>(toR)))) {
|
||||
mEPS = Square::fromCoordinates(move.to().file(), std::max(fromR, toR) - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mEPS = std::nullopt;
|
||||
}
|
||||
|
||||
void Board::pseudoLegalMoves(MoveVec &moves) const {
|
||||
(void) moves;
|
||||
|
Reference in New Issue
Block a user