- castling moves are stored as "king takes own rook" (from = king square, to = castling rook square) - per-colour castling rook squares (Board::castleRook), so DFRC (different back ranks for white/black) works - FEN parsing/printing: KQkq (X-FEN) and Shredder-FEN file letters - Board::CanCastle(): generic castling legality (empty paths, king not attacked, rook x-ray check) - MakeMove handles arbitrary king/rook start squares (king and rook may stay in place or swap through each other's squares) - UCI_Chess960 option: castling printed/parsed as king-takes-rook when on, standard e1g1 style otherwise (both are accepted when parsing) - viri format, perft castle check and castling right updates no longer assume a1/h1/a8/h8
110 lines
2.9 KiB
C++
110 lines
2.9 KiB
C++
#pragma once
|
|
#include <array>
|
|
#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<int, 64> mailbox;
|
|
|
|
std::array<Bitboard, 6> pieces;
|
|
std::array<Bitboard, 2> colors;
|
|
|
|
Bitboard occupied;
|
|
|
|
std::array<Bitboard, 2> pinned;
|
|
Bitboard checkers;
|
|
|
|
ACC::Update accUpdate;
|
|
bool mirroredWhite = false;
|
|
bool mirroredBlack = false;
|
|
|
|
std::array<Bitboard, 6> pieceThreats;
|
|
std::array<Bitboard, 2> colorThreats;
|
|
|
|
std::array<Move, MAX_MOVES> 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<int, 4> 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<Bitboard, 4> 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;
|
|
}; |