#pragma once #include #include "bitboard.h" #include "types.h" #include "move.h" #include "accumulator.h" constexpr int nullPieceType = 100; constexpr int noEPTarget = -1; constexpr int MAX_MOVES = 218; class Board { public: Board() { SetByFen(StartingFen); } std::array mailbox; std::array pieces; std::array colors; Bitboard occupied; std::array pinned; Bitboard checkers; ACC::Update accUpdate; bool mirroredWhite = false; bool mirroredBlack = false; std::array pieceThreats; std::array colorThreats; std::array moveList; int currentMoveIndex = 0; bool sideToMove = White; uint8_t castlingRights = 0; // Squares of the castling rooks, indexed by CastleIdx(color, kingSide). // Standard chess: h1, a1, h8, a8. Chess960 / DFRC positions override them while parsing the FEN. std::array castleRook = {h1, a1, h8, a8}; int enPassantTarget = noEPTarget; short positionIndex = 0; int halfMoves = 0; int fullMoves = 1; U64 hashKey = 0ULL; U64 pawnKey = 0ULL; U64 nonPawnKey = 0ULL; U64 majorKey = 0ULL; std::array checkZones; void Reset(); void SetByFen(std::string_view fen); std::string GetFen(); void PrintBoard(); void PrintNNUE(bool full = false); void AddMove(Move move); void ResetMoves(); void ListMoves(); ACC::BucketPair GetBuckets(); void RefreshAccumulator(ACC::AccumulatorPair& out) const; void UpdateAccumulator(ACC::AccStack& stack, int ply); void RefreshPerspective(ACC::FinnyTable& finny, bool perspective, ACC::Accumulator& out) const; void ApplyDeltaPerspective(bool perspective, ACC::Accumulator& dst, const ACC::Accumulator& src) const; void MarkAccumulatorDirty() { accUpdate.setRefresh(); } int GetPieceType(int square); int GetPieceColor(int square); bool InCheck(); void SetPiece(int piece, int square, bool color); void RemovePiece(int piece, int square, bool color); void Promote(int square, int pieceType, int color, bool isCapture); void MakeMove(Move move); bool InPossibleZug(); Bitboard AttacksTo(int square, Bitboard occupancy); bool IsSquareThreatened(bool side, int square); Bitboard CalcCheckers(); Bitboard CalcPinned(bool color); void CalcCheckZones(); bool GivesDirectCheck(Move &move); bool IsLegal(Move &move); bool IsPseudoLegal(Move &move); // Index of a castling right, same bit order as CASTLING_RIGHTS (white K, white Q, black K, black Q) static constexpr int CastleIdx(bool color, bool kingSide) { return color * 2 + (kingSide ? 0 : 1); } bool CanCastle(bool us, bool kingSide); void AddCastlingRight(char symbol); char CastlingSymbol(uint8_t right, char standardSymbol) const; };