From 96791e7ab670176d25e313caf2a428e21ccef168 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 10 Aug 2026 17:17:49 +0200 Subject: folowing the lint suggestions --- src/board/fen.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/board/fen.cpp') diff --git a/src/board/fen.cpp b/src/board/fen.cpp index 73201b8..dd503e0 100644 --- a/src/board/fen.cpp +++ b/src/board/fen.cpp @@ -39,22 +39,24 @@ static void SetPiece(int i, PieceType type, bool color, Game *g) { } g->pieces[i] = {.color = color, .type = type}; } - -void setBoardFen(const std::string fen, Game *g) { - for (int i = 0; i < 64; ++i) { - g->pieces[i] = {.color = false, .type = NONEPIECE}; +static void clearBoard(Game *g) { + for (auto &piece : g->pieces) { + piece = {.color = false, .type = NONEPIECE}; } g->blackCastleKing = false; g->blackCastleQueen = false; g->whiteCastleKing = false; g->whiteCastleQueen = false; +} +void setBoardFen(const std::string &fen, Game *g) { + clearBoard(g); // example fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 int file = 0; int rank = 7; Position enpassant = {}; - enum parserState { + enum parserState : std::uint8_t { BOARD, PLAYER_TO_MOVE, CASTLE, @@ -127,7 +129,7 @@ void setBoardFen(const std::string fen, Game *g) { } } if (parser_state == BOARD) { - if (isdigit(c)) { + if (isdigit(c) != 0) { int move = c - '0'; file += move; if (file > 8) { @@ -150,32 +152,32 @@ void setBoardFen(const std::string fen, Game *g) { continue; }; if (toupper(c) == 'N') { - SetPiece(rank * 8 + file, KNIGHT, isupper(c), g); + SetPiece((rank * 8) + file, KNIGHT, isupper(c) != 0, g); file++; continue; }; if (toupper(c) == 'R') { - SetPiece(rank * 8 + file, ROOK, isupper(c), g); + SetPiece((rank * 8) + file, ROOK, isupper(c) != 0, g); file++; continue; } if (toupper(c) == 'Q') { - SetPiece(rank * 8 + file, QUEEN, isupper(c), g); + SetPiece((rank * 8) + file, QUEEN, isupper(c) != 0, g); file++; continue; } if (toupper(c) == 'B') { - SetPiece(rank * 8 + file, BISHOP, isupper(c), g); + SetPiece((rank * 8) + file, BISHOP, isupper(c) != 0, g); file++; continue; } if (toupper(c) == 'P') { - SetPiece(rank * 8 + file, PAWN, isupper(c), g); + SetPiece((rank * 8) + file, PAWN, isupper(c) != 0, g); file++; continue; } if (toupper(c) == 'K') { - SetPiece(rank * 8 + file, KING, isupper(c), g); + SetPiece((rank * 8) + file, KING, isupper(c) != 0, g); file++; continue; } -- cgit v1.2.3