|
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:
-
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.
-
Active color. “
w ” means White moves next,
“b ” means Black.
-
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).
-
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.
-
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.
-
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
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1 rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2 rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2
download as text file
Output for Sample Input
rnbqkbnr pppppppp ........ ........ ........ ........ PPPPPPPP RNBQKBNR
rnbqkbnr pppppppp ........ ........ ....P... ........ PPPP.PPP RNBQKBNR
rnbqkbnr pp.ppppp ........ ..p..... ....P... ........ PPPP.PPP RNBQKBNR
rnbqkbnr pp.ppppp ........ ..p..... ....P... .....N.. PPPP.PPP RNBQKB.R
download as text file
|
|