diff options
| author | Adam <adammegarules1@gmail.com> | 2026-07-31 20:11:01 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-07-31 20:11:01 +0200 |
| commit | ee7815bad917cf880c147186a01679fb7ce46a8e (patch) | |
| tree | b645ea43ae002c1cc6cca37106b665390358f1b5 /src/board/fen.cpp | |
| parent | 061f2af803f7abfb4f655ef67769e79db705a3e1 (diff) | |
making stricter cmake list and then fixing bug it found
Diffstat (limited to 'src/board/fen.cpp')
| -rw-r--r-- | src/board/fen.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/board/fen.cpp b/src/board/fen.cpp index ccd8b6f..faa8f83 100644 --- a/src/board/fen.cpp +++ b/src/board/fen.cpp @@ -2,9 +2,11 @@ #include "board.hpp" #include <cassert> #include <cctype> +#include <cstdint> #include <cstdlib> #include <print> #include <string> +#include <sys/types.h> bool WHITE = true; bool BLACK = false; @@ -16,51 +18,51 @@ void setBoardFen(std::string fen, Game *g) { Position enpassant = {}; enum parserState { - POSITION, - TURN, + BOARD, + PLAYER_TO_MOVE, CASTLE, ENPASSANT, HALF_MOVE_CLOCK, FULL_MOVE_CLOCK, }; - parserState state = POSITION; + parserState parser_state = BOARD; for (uint i = 0; i < fen.length(); i++) { char c = fen[i]; if (c == ' ') { - if (state == POSITION) { - state = TURN; + if (parser_state == BOARD) { + parser_state = PLAYER_TO_MOVE; continue; } - if (state == TURN) { - state = CASTLE; + if (parser_state == PLAYER_TO_MOVE) { + parser_state = CASTLE; continue; } - if (state == CASTLE) { - state = ENPASSANT; + if (parser_state == CASTLE) { + parser_state = ENPASSANT; continue; } - if (state == ENPASSANT) { - state = HALF_MOVE_CLOCK; + if (parser_state == ENPASSANT) { + parser_state = HALF_MOVE_CLOCK; continue; } - if (state == HALF_MOVE_CLOCK) { - state = FULL_MOVE_CLOCK; + if (parser_state == HALF_MOVE_CLOCK) { + parser_state = FULL_MOVE_CLOCK; continue; } } - if (state == ENPASSANT) { + if (parser_state == ENPASSANT) { if (toupper(c) >= 'A' && toupper(c) <= 'H') { - enpassant.file = toupper(c) - 'A'; + enpassant.file = static_cast<uint8_t>(toupper(c) - 'A'); g->canEnpassant = true; } if (c >= '1' && c <= '8') { - enpassant.rank = c - '0'; + enpassant.rank = static_cast<uint8_t>(c - '0'); g->canEnpassant = true; } continue; } - if (state == CASTLE) { + if (parser_state == CASTLE) { if (c == '-') { g->blackCastleKing = false; g->blackCastleQueen = false; @@ -85,7 +87,7 @@ void setBoardFen(std::string fen, Game *g) { continue; } } - if (state == TURN) { + if (parser_state == PLAYER_TO_MOVE) { if (toupper(c) == 'W') { g->turn = WHITE; continue; @@ -95,7 +97,7 @@ void setBoardFen(std::string fen, Game *g) { continue; } } - if (state == POSITION) { + if (parser_state == BOARD) { if (isdigit(c)) { int move = c - '0'; file += move; |
