Programming contests

Magas szintű programozási nyelvek 1, egyéni verseny, 2014. április 13.

April 13, 2014 10:15 AM – April 13, 2014 3:15 PM

Forsyth–Edwards Notation

Forsyth–Edwards Notation (FEN) is a standard notation for describing a particular board position of a chess game. The purpose of FEN is to provide all the necessary information to restart a game from a particular position.

A FEN “record” defines a particular game position, all in one text line and using only the ASCII character set. A FEN record contains six fields. The separator between fields is a space. The fields are:

  1. Piece placement (from white's perspective). Each rank is described, starting with rank 8 and ending with rank 1; within each rank, the contents of each square are described from file a through file h. Following the Standard Algebraic Notation (SAN), each piece is identified by a single letter taken from the standard English names (“P” for pawn, “N” for knight, “B” for bishop, “R” for rook, “Q” for queen, and “K” for king). White pieces are designated using uppercase letters (“PNBRQK”), while black pieces use lowercase (“pnbrqk”). Blank squares are noted using digits 1 through 8 (the number of blank squares), and “/” separates ranks.
  2. Active color. “w” means White moves next, “b” means Black.
  3. Castling availability. If neither side can castle, this is “-”. Otherwise, this has one or more letters: “K” (White can castle kingside), “Q” (White can castle queenside), “k” (Black can castle kingside), and/or “q” (Black can castle queenside).
  4. En passant target square in algebraic notation. If there's no en passant target square, this is “”. If a pawn has just made a two-square move, this is the position “behind” the pawn. This is recorded regardless of whether there is a pawn in position to make an en passant capture.
  5. Halfmove clock. This is the number of halfmoves since the last pawn advance or capture. This is used to determine if a draw can be claimed under the fifty-move rule.
  6. Fullmove number. The number of full moves. It starts at 1 and is incremented after Black's move.

You are to write a program that, given a set of FEN records, prints the corresponding chessboard states.

Input Specification

The input will consist of a series of FEN records, one record per line. You must read the input until you reach the end of file.

Output Specification

For each FEN record, output the chessboard represented by the given FEN record. Each board should consist of 8 lines of 8 characters each. A “.” character should represent an empty square. Uppercase and lowercase letters (as defined above) should represent the pieces. There should be an empty line between two consecutive boards.

Do not print a blank line after the last chessboard.

Sample Input

  1. rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
  2. rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1
  3. rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2
  4. rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2
download as text file

Output for Sample Input

  1. rnbqkbnr
  2. pppppppp
  3. ........
  4. ........
  5. ........
  6. ........
  7. PPPPPPPP
  8. RNBQKBNR
  9. rnbqkbnr
  10. pppppppp
  11. ........
  12. ........
  13. ....P...
  14. ........
  15. PPPP.PPP
  16. RNBQKBNR
  17. rnbqkbnr
  18. pp.ppppp
  19. ........
  20. ..p.....
  21. ....P...
  22. ........
  23. PPPP.PPP
  24. RNBQKBNR
  25. rnbqkbnr
  26. pp.ppppp
  27. ........
  28. ..p.....
  29. ....P...
  30. .....N..
  31. PPPP.PPP
  32. RNBQKB.R
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019