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 | |
| parent | 061f2af803f7abfb4f655ef67769e79db705a3e1 (diff) | |
making stricter cmake list and then fixing bug it found
Diffstat (limited to 'src/board')
| -rw-r--r-- | src/board/board.cpp | 4 | ||||
| -rw-r--r-- | src/board/board.hpp | 8 | ||||
| -rw-r--r-- | src/board/fen.cpp | 40 |
3 files changed, 27 insertions, 25 deletions
diff --git a/src/board/board.cpp b/src/board/board.cpp index 8c8e423..af313d0 100644 --- a/src/board/board.cpp +++ b/src/board/board.cpp @@ -82,11 +82,11 @@ UndoMove MakeMove(Move move, Game *g) { // Adding enpassant if (piece.type == PAWN) { Position to = move.To; - to.rank -= (piece.color ? -2 : 2); + to.rank -= static_cast<uint8_t>(piece.color ? -2 : 2); if (to == move.From) { g->canEnpassant = true; Position target = move.From; - target.rank += piece.color ? -1 : 1; + target.rank += static_cast<uint8_t>(piece.color ? -1 : 1); g->enPassant = target; }; } diff --git a/src/board/board.hpp b/src/board/board.hpp index 7a9779a..5d0d913 100644 --- a/src/board/board.hpp +++ b/src/board/board.hpp @@ -27,8 +27,8 @@ struct Piece { }; struct Position { - uint8_t rank = 0; - uint8_t file = 0; + int rank = 0; + int file = 0; bool operator==(const Position &) const = default; }; @@ -58,8 +58,8 @@ struct Game { bool whiteCastleQueen = false; bool blackCastleKing = false; bool blackCastleQueen = false; - uint8_t halfMoveClock = 0; - uint16_t MoveClock = 0; + int halfMoveClock = 0; + int MoveClock = 0; Position enPassant; bool canEnpassant = false; GameState state = TURN; 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; |
