From fcc0dc87f04403c8073ab769d3046d32342e6c2a Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 18 Aug 2026 14:22:55 +0200 Subject: featuare(fen): validating king counts before accepting fen string --- src/board/fen.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/board/fen.cpp') diff --git a/src/board/fen.cpp b/src/board/fen.cpp index e020e78..f44719a 100644 --- a/src/board/fen.cpp +++ b/src/board/fen.cpp @@ -2,8 +2,10 @@ #include "board.hpp" #include #include +#include #include #include +#include #include #include #include @@ -185,5 +187,18 @@ void setBoardFen(const std::string &fen, Game *g) { break; } g->enPassant = enpassant; + updateBitboards(g); + + int whiteKingCount = __builtin_popcountll(g->PieceBitboards[true][KING]); + int blackKingCount = __builtin_popcountll(g->PieceBitboards[false][KING]); + + if (whiteKingCount != 1) { + std::cerr << "ERROR: expected exactly one white king\n"; + exit(1); + } + if (blackKingCount != 1) { + std::cerr << "ERROR: expected exactly one black king\n"; + exit(1); + } } -- cgit v1.2.3