diff options
| author | Adam <adammegarules1@gmail.com> | 2026-08-18 14:22:55 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-08-18 14:22:55 +0200 |
| commit | fcc0dc87f04403c8073ab769d3046d32342e6c2a (patch) | |
| tree | f9b0a85e6a3845e3ed0677ce8d667c988b7474be | |
| parent | dd4f969d156bbaa546911b3951211bb2245182ad (diff) | |
featuare(fen): validating king counts before accepting fen string
| -rw-r--r-- | src/board/fen.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
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 <cassert> #include <cctype> +#include <cstdint> #include <cstdlib> #include <cstring> +#include <iostream> #include <print> #include <string> #include <sys/types.h> @@ -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); + } } |
