62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
#ifndef CHESS_ENGINE_BOARD_HPP
|
|
#define CHESS_ENGINE_BOARD_HPP
|
|
|
|
#include "Piece.hpp"
|
|
#include "Square.hpp"
|
|
#include "Move.hpp"
|
|
#include "CastlingRights.hpp"
|
|
|
|
#include <optional>
|
|
#include <iosfwd>
|
|
#include <vector>
|
|
|
|
#define BB_NUM 12 // 6 pieces, 2 colors
|
|
|
|
class Board {
|
|
public:
|
|
|
|
using Optional = std::optional<Board>;
|
|
using MoveVec = std::vector<Move>;
|
|
|
|
using BitBoard = uint64_t;
|
|
|
|
Board();
|
|
|
|
void setPiece(const Square &square, const Piece::Optional &piece);
|
|
Piece::Optional piece(const Square &square) const;
|
|
void setTurn(PieceColor turn);
|
|
PieceColor turn() const;
|
|
void setCastlingRights(CastlingRights cr);
|
|
CastlingRights castlingRights() const;
|
|
void setEnPassantSquare(const Square::Optional &square);
|
|
Square::Optional enPassantSquare() const;
|
|
|
|
void makeMove(const Move &move);
|
|
|
|
void pseudoLegalMoves(MoveVec &moves) const;
|
|
void pseudoLegalMovesFrom(const Square &from, MoveVec &moves) const;
|
|
|
|
private:
|
|
|
|
BitBoard mPieceBBs[BB_NUM] = {};
|
|
PieceColor mTurn = PieceColor::White;
|
|
CastlingRights mCr;
|
|
unsigned mEPS = 64;
|
|
|
|
static inline void clearIndex(BitBoard &b, unsigned i) {
|
|
b &= ~(1ULL << i);
|
|
}
|
|
|
|
static inline void setIndex(BitBoard &b, unsigned i) {
|
|
b |= 1ULL << i;
|
|
}
|
|
|
|
static inline BitBoard indexToBitBoard(unsigned i) {
|
|
return (1ULL << i);
|
|
}
|
|
};
|
|
|
|
std::ostream &operator<<(std::ostream &os, const Board &board);
|
|
|
|
#endif
|