aboutsummaryrefslogtreecommitdiff
path: root/src/board/fen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/board/fen.cpp')
-rw-r--r--src/board/fen.cpp26
1 files changed, 14 insertions, 12 deletions
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;
}