fully support FEN strings now
Some checks failed
pre-release / Pre Release (push) Has been cancelled
tagged-release / Tagged Release (push) Has been cancelled

This commit is contained in:
Karma Riuk
2025-02-02 23:05:42 +01:00
parent 22acfc5027
commit 84c3af2bb1
3 changed files with 28 additions and 8 deletions

View File

@ -82,6 +82,15 @@ Board Board::setup_fen_position(std::string fen) {
index++;
}
// -- Half move clock
index = fen.find(' ', index) + 1;
board.n_half_moves =
std::stoi(fen.substr(index, fen.find(' ', index + 1) - index));
// -- Full move number
index = fen.find(' ', index) + 1;
board.n_full_moves = std::stoi(fen.substr(index));
return board;
}
@ -127,7 +136,7 @@ std::string Board::to_fen() const {
ret += white_to_play ? 'w' : 'b';
ret += " ";
// Castling Rights
// -- Castling Rights
if (w_castle_rights == CastleSide::NeitherSide
&& b_castle_rights == CastleSide::NeitherSide)
ret += '-';
@ -143,10 +152,18 @@ std::string Board::to_fen() const {
}
ret += ' ';
// En passant target
// -- En passant target
ret += en_passant_target == -1
? "-"
: Coords::from_index(en_passant_target).to_algebraic();
ret += ' ';
// -- Half move clock
ret += std::to_string(n_half_moves);
ret += ' ';
// -- Full moves number
ret += std::to_string(n_full_moves);
return ret;
}

View File

@ -16,6 +16,8 @@ struct Board {
int8_t w_castle_rights = CastleSide::NeitherSide;
int8_t b_castle_rights = CastleSide::NeitherSide;
int8_t en_passant_target = -1;
uint8_t n_half_moves = 0;
uint8_t n_full_moves = 0;
static Board setup_fen_position(std::string fen);