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.cpp40
1 files changed, 21 insertions, 19 deletions
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;