123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #ifndef CHESSY_CHESSGAME_H
- #define CHESSY_CHESSGAME_H
- #include <vector>
- #include <string>
- #include "Board.h"
- #include "TranspositionTable.h"
- namespace chessy
- {
- struct MoveInfo;
- struct UndoInfo;
- class ChessGame;
- }
- /*!
- * This structure holds additional information about a move.
- */
- struct chessy::MoveInfo
- {
- //! the move itself
- Move move;
- //! the type of the piece that was moved
- PieceType movedPiece;
- //! if the move is an en-passant move, this field holds the square of
- //! the pawn, that was captured. Otherwise this index should be zero.
- //Index enPassantTarget;
- MoveInfo(void) = default;
- MoveInfo(Move move, const ChessGame& cg);
- };
- struct chessy::UndoInfo
- {
- Bitboard before;
- Bitboard beforeCaptured;
- Bitboard promotionBefore;
- HashValue hash;
- PieceType type;
- PieceType captured;
- PieceType promotion;
- Index enPassantBefore;
- uint8_t reversibleHalfMoves;
- uint8_t castlingRights;
- };
- class chessy::ChessGame
- {
- Board board;
- short reversibleHalfMoves = 0;
- //! stores the castling rights according to the following scheme:
- //! <b> XXXXQKqk </b>,
- //! where X is an unused bit, Q and K store weather black can castle
- //! to queen side/king side and q and k store the same for white.
- uint8_t castlingRights = 0xF;
- //! file of en-passant-capturable pawn
- // -1 for no en passant possible
- int8_t enPassant = -1;
- Side turn = WHITE_SIDE;
- int moveCount = 1;
- //! holds the zobrist hash value for the current position
- HashValue hash;
- std::vector<HashValue> history;
- public:
- ChessGame(void);
- ChessGame(const std::string& fenString);
- ChessGame(const ChessGame&) = default;
- ~ChessGame(void) = default;
- inline const Board& getBoard(void) const { return board; }
- inline Board& getBoard(void) { return board; }
- inline bool getCanCastleKingSide(Side side) const
- {
- return castlingRights & (1 << (side == BLACK_SIDE ? 2 : 0));
- }
- inline void setCanCastleKingSide(Side side, bool canCastle)
- {
- castlingRights ^= (castlingRights ^ (canCastle ? -1 : 0)) &
- (1 << (side == BLACK_SIDE ? 2 : 0));
- }
- inline bool getCanCastleQueenSide(Side side) const
- {
- return castlingRights & (1 << (side == BLACK_SIDE ? 3 : 1));
- }
- inline void setCanCastleQueenSide(Side side, bool canCastle)
- {
- castlingRights ^= (castlingRights ^ (canCastle ? -1 : 0)) &
- (1 << (side == BLACK_SIDE ? 3 : 1));
- }
- inline int getCastlingRights(void) const { return castlingRights; }
- inline HashValue getHash(void) const { return hash; }
- inline const std::vector<HashValue>& getHistory(void) const { return history; }
- void move(Move move);
- inline Side getTurn(void) const { return turn; }
- void loadFromFen(const std::string& fenString);
- std::string generateFen(void) const;
- inline Index getEnPassantIndex(void) const { return enPassant; }
- UndoInfo doMove(const MoveInfo& mi);
- void undoMove(const UndoInfo& ui);
- };
- #endif // CHESSY_CHESSGAME_H
|