From ee7815bad917cf880c147186a01679fb7ce46a8e Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 31 Jul 2026 20:11:01 +0200 Subject: making stricter cmake list and then fixing bug it found --- src/board/board.cpp | 4 ++-- src/board/board.hpp | 8 ++++---- src/board/fen.cpp | 40 +++++++++++++++++++++------------------- 3 files changed, 27 insertions(+), 25 deletions(-) (limited to 'src/board') 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(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(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 #include +#include #include #include #include +#include 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(toupper(c) - 'A'); g->canEnpassant = true; } if (c >= '1' && c <= '8') { - enpassant.rank = c - '0'; + enpassant.rank = static_cast(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; -- cgit v1.2.3