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;
- }
- struct chessy::MoveInfo
- {
-
- Move move;
-
- PieceType movedPiece;
-
-
-
- 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;
-
-
-
-
- uint8_t castlingRights = 0xF;
-
-
- int8_t enPassant = -1;
- Side turn = WHITE_SIDE;
- int moveCount = 1;
-
- 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
|