diff options
| author | Adam <adammegarules1@gmail.com> | 2026-08-10 17:17:49 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-08-10 17:17:49 +0200 |
| commit | 96791e7ab670176d25e313caf2a428e21ccef168 (patch) | |
| tree | d1f16b1ebdfe00cda8f189f1d50cfb96059bdc14 /src/board | |
| parent | 5ad271953558c4b9212137c60187bc018e2f45f1 (diff) | |
folowing the lint suggestions
Diffstat (limited to 'src/board')
| -rw-r--r-- | src/board/board.cpp | 11 | ||||
| -rw-r--r-- | src/board/board.hpp | 1 | ||||
| -rw-r--r-- | src/board/fen.cpp | 26 | ||||
| -rw-r--r-- | src/board/fen.hpp | 2 |
4 files changed, 22 insertions, 18 deletions
diff --git a/src/board/board.cpp b/src/board/board.cpp index c02aac5..ad5ab12 100644 --- a/src/board/board.cpp +++ b/src/board/board.cpp @@ -7,10 +7,10 @@ #include "moves.hpp" #include "zobrist.hpp" -int PositionToIndex(Position i) { return i.rank * 8 + i.file; } +int PositionToIndex(Position i) { return (i.rank * 8) + i.file; } -Position FindKing(Game *b, bool color) { - return IndexToPosition(__builtin_ctzll(b->PieceBitboards[color][KING])); +Position FindKing(Game *g, bool color) { + return IndexToPosition(__builtin_ctzll(g->PieceBitboards[color][KING])); } UndoMove MakeMove(Move move, Game *g) { UndoMove undo = {}; @@ -284,7 +284,10 @@ void UnMakeMove(UndoMove undo, Game *g) { rookTo.file = 7; g->pieces[PositionToIndex(rookTo)] = g->pieces[PositionToIndex(rookFrom)]; - g->pieces[PositionToIndex(rookFrom)] = {false, NONEPIECE}; + g->pieces[PositionToIndex(rookFrom)] = { + .color = false, + .type = NONEPIECE, + }; } else { // d -> a Position rookFrom = undo.from; diff --git a/src/board/board.hpp b/src/board/board.hpp index 3a8a899..6f72e56 100644 --- a/src/board/board.hpp +++ b/src/board/board.hpp @@ -1,7 +1,6 @@ #ifndef SRC_BOARD_H_ #define SRC_BOARD_H_ -#include <array> #include <cstdint> #include <unordered_map> 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; } diff --git a/src/board/fen.hpp b/src/board/fen.hpp index 7af3db3..f52afe5 100644 --- a/src/board/fen.hpp +++ b/src/board/fen.hpp @@ -5,5 +5,5 @@ #include "board.hpp" -void setBoardFen(const std::string fen, Game *b); +void setBoardFen(const std::string &fen, Game *b); #endif /* SRC_FEN_H_ */ |
