[Board] Initial pseudoLegalMovesFrom
This commit is contained in:
45
Board.cpp
45
Board.cpp
@@ -150,8 +150,41 @@ void Board::pseudoLegalMoves(MoveVec &moves) const {
|
||||
}
|
||||
|
||||
void Board::pseudoLegalMovesFrom(const Square &from, Board::MoveVec &moves) const {
|
||||
(void) from;
|
||||
(void) moves;
|
||||
auto fromBB = BitBoard::fromIndex(from.index());
|
||||
|
||||
if (!(fromBB & mPieceBBs[toIndex(mTurn)])) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto p = Piece(mTurn, pieceType(fromBB));
|
||||
|
||||
BitBoard movesBB;
|
||||
switch (p.type()) {
|
||||
case PieceType::Pawn:mMoveGenerator->generatePawnMoves(from, mEPS, mTurn, moves);
|
||||
return;
|
||||
case PieceType::Knight: break;
|
||||
case PieceType::Bishop:movesBB = BitBoard::bishopAttacks(fromBB, ~*mOccupiedBB) & ~mPieceBBs[toIndex(mTurn)];
|
||||
break;
|
||||
case PieceType::Rook: break;
|
||||
case PieceType::Queen: break;
|
||||
|
||||
case PieceType::King:movesBB = BitBoard::kingAttacks(fromBB) & ~mPieceBBs[toIndex(mTurn)];
|
||||
if (hasCastlingRights()) {
|
||||
if (mTurn == PieceColor::White) {
|
||||
movesBB |= BitBoard::castlingMoves(fromBB, ~mPieceBBs[toIndex(PieceType::Rook)], ~*mOccupiedBB)
|
||||
& WhiteCastlingRank;
|
||||
} else {
|
||||
movesBB |= BitBoard::castlingMoves(fromBB, ~mPieceBBs[toIndex(PieceType::Rook)], ~*mOccupiedBB)
|
||||
& BlackCastlingRank;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
while (movesBB) {
|
||||
auto to = Square(movesBB.pop());
|
||||
moves.emplace_back(from, to, std::nullopt);
|
||||
}
|
||||
}
|
||||
void Board::handleCastlingRights(const Piece &piece, const BitBoard &bb) {
|
||||
if (piece.type() != PieceType::King && piece.type() != PieceType::Rook) {
|
||||
@@ -200,6 +233,14 @@ bool Board::isMoveCastling(const BitBoard &from, const BitBoard &to, const Piece
|
||||
|
||||
return from & BitBoard::fromIndex(E8);
|
||||
}
|
||||
constexpr bool Board::hasCastlingRights() const {
|
||||
switch (mTurn) {
|
||||
case PieceColor::White:return (mCR & CastlingRights::White) != CastlingRights::None;
|
||||
case PieceColor::Black:return (mCR & CastlingRights::Black) != CastlingRights::None;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const Board &board) {
|
||||
// For debugging only, performance isn't important
|
||||
|
Reference in New Issue
Block a user