implemented the en passant target support for FEN
strings
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user