feat: en passant generally implemented
This commit is contained in:
parent
1842e25918
commit
10a4dcb60b
4 changed files with 53 additions and 12 deletions
|
|
@ -48,10 +48,12 @@ class Board {
|
|||
* It is a 2D vector of Piece types, or nullptr for empty squares
|
||||
* @image html boardGrid.svg "Logical diagram of boardGrid vector" */
|
||||
Players playerTurn;
|
||||
Square enPassantTargetSquare = {INVALID_RANK, INVALID_FILE};
|
||||
|
||||
// let's get super object-oriented, baby
|
||||
// these help the getters and setters access the boardGrid
|
||||
// and also make them shorter and less duplicative
|
||||
std::unique_ptr<Piece>& at(int r, int f) {
|
||||
std::unique_ptr<Piece> &at(int r, int f) {
|
||||
return boardGrid[r][f];
|
||||
}
|
||||
|
||||
|
|
@ -59,11 +61,11 @@ class Board {
|
|||
return boardGrid[r][f];
|
||||
}
|
||||
|
||||
std::unique_ptr<Piece> &at(const Square& sq) {
|
||||
std::unique_ptr<Piece> &at(const Square &sq) {
|
||||
return boardGrid[static_cast<int>(sq.rank)][static_cast<int>(sq.file)];
|
||||
}
|
||||
|
||||
const std::unique_ptr<Piece> &at(const Square& sq) const {
|
||||
const std::unique_ptr<Piece> &at(const Square &sq) const {
|
||||
return boardGrid[static_cast<int>(sq.rank)][static_cast<int>(sq.file)];
|
||||
}
|
||||
public:
|
||||
|
|
@ -73,40 +75,50 @@ class Board {
|
|||
// These are to allow Piece to access Board in a controlled way
|
||||
// instead of adding a friend declaration for every subclass
|
||||
// ----- Getters -----
|
||||
Piece* getPieceAt(int r, int f) {
|
||||
Piece *getPieceAt(int r, int f) {
|
||||
return at(r, f).get();
|
||||
}
|
||||
const Piece* getPieceAt(int r, int f) const {
|
||||
const Piece *getPieceAt(int r, int f) const {
|
||||
return at(r, f).get();
|
||||
}
|
||||
|
||||
Piece* getPieceAt(const Square& sq) {
|
||||
Piece *getPieceAt(const Square &sq) {
|
||||
return at(sq).get();
|
||||
}
|
||||
const Piece* getPieceAt(const Square& sq) const {
|
||||
const Piece *getPieceAt(const Square &sq) const {
|
||||
return at(sq).get();
|
||||
}
|
||||
Square getEnPassantTargetSquare() const {
|
||||
return enPassantTargetSquare;
|
||||
}
|
||||
|
||||
// ----- Setters -----
|
||||
void setPieceAt(int r, int f, std::unique_ptr<Piece> piece) {
|
||||
at(r, f) = std::move(piece);
|
||||
}
|
||||
void setPieceAt(const Square& sq, std::unique_ptr<Piece> piece) {
|
||||
void setPieceAt(const Square &sq, std::unique_ptr<Piece> piece) {
|
||||
at(sq) = std::move(piece);
|
||||
}
|
||||
|
||||
void clearSquare(int r, int f) {
|
||||
at(r, f).reset();
|
||||
}
|
||||
void clearSquare(const Square& sq) {
|
||||
void clearSquare(const Square &sq) {
|
||||
at(sq).reset();
|
||||
}
|
||||
|
||||
void setEnPassantTargetSquare(Square sq) {
|
||||
enPassantTargetSquare = sq;
|
||||
}
|
||||
void clearEnPassantTargetSquare() {
|
||||
enPassantTargetSquare = {INVALID_RANK, INVALID_FILE};
|
||||
}
|
||||
|
||||
// ----- Utility -----
|
||||
bool isSquareEmpty(int r, int f) const {
|
||||
return at(r, f) == nullptr;
|
||||
}
|
||||
bool isSquareEmpty(const Square& sq) const {
|
||||
bool isSquareEmpty(const Square &sq) const {
|
||||
return at(sq) == nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -228,7 +228,6 @@ class Pawn : public Piece {
|
|||
virtual std::vector<Move> getLegalMoves(const Square &from, Board &board) const override;
|
||||
void promote(const Square &promotionSquare, Board &board, PieceType promoteTo);
|
||||
protected:
|
||||
bool vulnEnPassant = false;
|
||||
bool firstMove = true;
|
||||
};
|
||||
#endif // PIECE_HPP
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue