#ifndef SRC_BOARD_H_ #define SRC_BOARD_H_ #include #include #include enum PieceType : std::uint8_t { NONEPIECE, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING, }; enum GameState : std::uint8_t { TURN, WHITE_WON, BLACK_WON, DRAW, }; struct Piece { bool color = false; PieceType type = NONEPIECE; }; struct Position { int rank = 0; int file = 0; bool operator==(const Position &) const = default; }; /* * things here is a diagram for it uint16_t: XXFFFFFFTTTTTT00, XX for promotion * flag F for from position T for to position, and 00 for empty ones. */ uint16_t CreateMove(uint8_t from, uint8_t to, PieceType promotion = NONEPIECE); PieceType getPromotionTypeFromMove(uint16_t move); uint8_t getFromValueFromMove(uint16_t move); uint8_t getToValueFromMove(uint16_t move); enum Flag : std::uint8_t { EXACT, LOWERBOUND, UPPERBOUND }; struct TranspositionsEntry { int depth = -1; int Eval = 0; Flag flag = EXACT; uint16_t bestMove = {}; }; struct Game { Piece pieces[64]; uint64_t PieceBitboard = 0; // used for quicly iterating over all squares uint64_t WhitePieceBitboard = 0; uint64_t BlackPieceBitboard = 0; uint64_t PieceBitboards[2][7] = {}; bool turn = true; // 1 white; 0 black bool whiteCastleKing = false; bool whiteCastleQueen = false; bool blackCastleKing = false; bool blackCastleQueen = false; int halfMoveClock = 0; int MoveClock = 0; Position enPassant; bool canEnpassant = false; GameState state = TURN; uint64_t hash = 0; std::vector history; std::unordered_map *Transpositions = nullptr; }; bool isRepetionDraw(uint64_t key, Game *g); struct Undo { Piece movedPiece; Piece capturedPiece; uint8_t from; uint8_t to; bool wasEnPassantCapture = false; Position enPassantCapturedSquare; Piece enPassantCapturedPiece; bool oldTurn; bool oldCanEnpassant; Position oldEnPassant; bool OldWhiteCastleKing; bool OldWhiteCastleQueen; bool OldBlackCastleKing; bool OldBlackCastleQueen; int oldHalfMoveClock; int oldMoveClock; uint64_t ZobristKey; GameState oldState; // castling bool wasCastle = false; bool CastledSide = false; // 0 for queen side, 1 for king side }; int PositionToIndex(Position i); Undo MakeMove(uint16_t move, Game *g); void UndoMove(Undo undo, Game *g); Position FindKing(const Game &g, bool color); #endif /* SRC_BOARD_H_ */