From fa99aa2d53eb1f784b6e7bb4971cf36092488957 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 10 Aug 2026 15:04:37 +0200 Subject: making fen parser be self contained --- src/board/fen.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/board/fen.cpp') diff --git a/src/board/fen.cpp b/src/board/fen.cpp index c4c5e7a..5f27e68 100644 --- a/src/board/fen.cpp +++ b/src/board/fen.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -10,7 +11,39 @@ bool WHITE = true; bool BLACK = false; +static void updateBitboards(Game *g) { + g->PieceBitboard = 0; + g->WhitePieceBitboard = 0; + g->BlackPieceBitboard = 0; + std::memset(g->PieceBitboards, 0, sizeof(g->PieceBitboards)); + for (uint8_t i = 0; i < 64; i++) { + Piece piece = g->pieces[i]; + if (piece.type == NONEPIECE) { + continue; + } + g->PieceBitboards[piece.color][piece.type] |= (1ULL << i); + + if (piece.color) { + g->WhitePieceBitboard |= (1ULL << i); + } else { + g->BlackPieceBitboard |= (1ULL << i); + } + } + g->PieceBitboard = g->WhitePieceBitboard | g->BlackPieceBitboard; +} +static void SetPiece(int i, PieceType type, bool color, Game *g) { + g->pieces[i] = {.color = color, .type = type}; +} + void setBoardFen(const std::string fen, Game *g) { + for (int i = 0; i < 64; ++i) { + g->pieces[i] = {.color = false, .type = NONEPIECE}; + } + g->blackCastleKing = false; + g->blackCastleQueen = false; + g->whiteCastleKing = false; + g->whiteCastleQueen = false; + // example fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 int file = 0; int rank = 7; @@ -145,5 +178,5 @@ void setBoardFen(const std::string fen, Game *g) { break; } g->enPassant = enpassant; - UpdateHelpers(g); + updateBitboards(g); } -- cgit v1.2.3