Castling, en passant and FEN out (Chess)

Add the special moves. Castling (e1g1, e1c1, e8g8, e8c8) needs the right in the FEN (KQkq), the rook on its square, empty squares between, and the king not in check and not crossing or landing on an attacked square; the rook jumps over. Moving the king loses both rights, moving or capturing a rook loses that side’s right. En passant: after a double pawn push, the square passed over (FEN field 4) can be captured into by an enemy pawn on the next move only. After the board, print the final FEN (with castling rights or -, the en passant square or -, the half-move clock (reset by pawn moves and captures) and the move number (up after black moves)).

Input: As before.

Output: As before, plus the final FEN.

Difficulty: Hard. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Keep castling rights and the en passant square in your state; update them in the make-move function.

More Chess practice