[Board] Initial pseudoLegalMovesFrom

This commit is contained in:
2022-12-22 18:38:16 +01:00
parent b64530cb3d
commit 4f96d189fa

View File

@@ -150,8 +150,41 @@ void Board::pseudoLegalMoves(MoveVec &moves) const {
} }
void Board::pseudoLegalMovesFrom(const Square &from, Board::MoveVec &moves) const { void Board::pseudoLegalMovesFrom(const Square &from, Board::MoveVec &moves) const {
(void) from; auto fromBB = BitBoard::fromIndex(from.index());
(void) moves;
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) { void Board::handleCastlingRights(const Piece &piece, const BitBoard &bb) {
if (piece.type() != PieceType::King && piece.type() != PieceType::Rook) { 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); 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) { std::ostream &operator<<(std::ostream &os, const Board &board) {
// For debugging only, performance isn't important // For debugging only, performance isn't important