implemented the en passant target support for FEN

strings
This commit is contained in:
Karma Riuk
2025-02-02 22:52:23 +01:00
parent 2493892b05
commit 1ff4b6b1f4
4 changed files with 24 additions and 6 deletions

View File

@ -73,6 +73,16 @@ Board Board::setup_fen_position(std::string fen) {
}
}
// -- En passant target
if (fen[index] != '-') {
Coords c = Coords::from_algebraic(fen.substr(index, index + 2));
index += 2;
board.en_passant_target = c.to_index();
} else {
index++;
}
return board;
}
@ -131,6 +141,12 @@ std::string Board::to_fen() const {
if (b_castle_rights & CastleSide::QueenSide)
ret += 'q';
}
ret += ' ';
// En passant target
ret += en_passant_target == -1
? "-"
: Coords::from_index(en_passant_target).to_algebraic();
return ret;
}

View File

@ -15,6 +15,7 @@ struct Board {
bool white_to_play = true;
int8_t w_castle_rights = CastleSide::NeitherSide;
int8_t b_castle_rights = CastleSide::NeitherSide;
int8_t en_passant_target = -1;
static Board setup_fen_position(std::string fen);

View File

@ -6,5 +6,6 @@ int main(int argc, char* argv[]) {
std::string pos =
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
Board b = Board::setup_fen_position(pos);
sizeof(b);
return 0;
}