Mr Short likes to play chess. Mr Short is also a very traditional man. Hence, Mr Short is disturbed by the recent trend of using Algebraic notation in modern chess, and he would rather use Descriptive notation, like his father and his father's father before him.
To simplify this challenge, I chose not to deal with disambiguaties (as in, when two pieces can move to the same square, or can capture the same piece.) Also there is no dealing with en passant, promotion, or Castling.
Algebraic notation for the uninitiated
- The board squares are numbered from
a1at the bottom left to
h8as the top right. The letters represent the files (columns) while the numbers represent the ranks (rows). The white King is placed in the beginning of the game at the square
- A move consists of the piece that moved + the destination square. For example, a King moving to
- If the piece that had moved is a Pawn, the piece letter is omitted. For example, the starting move Pawn to
e4is written as
- If the move is a capture, then the
xletter is inserted between the piece and the destination square. For example, a Queen capturing at
f7is annotated as
- If the capturing piece is a Pawn, since it moves diagonally, the notation records the file the Pawn originated from. For example, when the Pawn at
c4captures a piece at
d5, the move is annotated as
- Piece symbols are
Nfor Knight, and
Rfor Rook. Pawns have no symbols.
- Other annotations include
+for check, and
#for checkmate. A Pawn moving to f7 and giving check is
f7+. Note lack of space.
Descriptive notation for the uninitiated
- The files are described by the piece that starts on it. For example, what would be the
efile in Algebraic, becomes the King file, or, for short,
K. The other files are marked by their side, then the piece. So file
his the King's Rook's file, or
- The ranks are numbered from the point of view of the moving player. What would be the fourth rank in Algebraic, is the fourth rank for white, but the fifth rank for black.
- It follows that the square
K4for the white player and
K5for the black player. The square
KB7for the white player and
KB2for the black player.
- A move is annotated by the piece moving, then a dash, then the target square. So a Pawn moving to
P-K4. A Queen moving to
- A capture is annotated by the capturing piece, then
x, then the captured piece. Therefore a Bishop capturing a Pawn is
BxP. Usually you need to mark which Pawn is being captured, but ignore this for sake of simplicity.
- Piece symbols are
Ktfor Knight (note the different symbol),
Rfor Rook, and
- Other annotations include
chfor check and
matefor checkmate. A Pawn moving to
KB7and giving check is
P-KB7 ch. Note the space.
A string of algebraic notation moves, delineated by spaces. There are no move numbers. For example, the Fool's mate goes like this:
f3 e5 g4 Qh4#
Or the game Teed vs Delmar, from the same Wikipedia page:
d4 f5 Bg5 h6 Bf4 g5 Bg3 f4 e3 h5 Bd3 Rh6 Qxh5+ Rxh5 Bg6#
The Immortal game.
e4 e5 f4 exf4 Bc4 Qh4+ Kf1 b5 Bxb5 Nf6 Nf3 Qh6 d3 Nh5 Nh4 Qg5 Nf5 c6 g4 Nf6 Rg1 cxb5 h4 Qg6 h5 Qg5 Qf3 Ng8 Bxf4 Qf6 Nc3 Bc5 Nd5 Qxb2 Bd6 Bxg1 e5 Qxa1+ Ke2 Na6 Nxg7+ Kd8 Qf6+ Nxf6 Be7#
You may assume that input is always a valid game. All moves are in the correct order, and no extraneous data is present. No moves will include disambiguation.
For example, The Evergreen game despite being, obviously, a valid game, is not going to be input due to the 19th move,
You may also assume that all input move lists start from the starting position.
A move list, with a similar format, in Descriptive notation.
For example, the Fool's mate:
P-KB3 P-K4 P-KKt4 Q-KR5 mate
Teed vs Delmar:
P-Q4 P-KB4 B-KKt5 P-KR3 B-KB4 P-KKt4 B-KKt3 P-KB5 P-K3 P-KR4 B-Q3 R-KR3 QxP ch RxQ B-KKt6 mate
The Immortal Game:
P-K4 P-K4 P-KB4 PxP B-QB4 Q-KR5 ch K-KB1 P-QKt4 BxP Kt-KB3 Kt-KB3 Q-KR3 P-Q3 Kt-KR4 Kt-KR4 Q-KKt4 Kt-KB5 P-QB3 P-KKt4 Kt-KB4 R-KKt1 PxB P-KR4 Q-KKt3 P-KR5 Q-KKt4 Q-KB3 Kt-KKt1 BxP Q-KB3 Kt-QB3 B-QB4 Kt-Q5 QxP B-Q6 BxR P-K5 QxR ch K-K2 Kt-QR3 KtxP ch K-Q1 Q-KB6 ch KtxQ B-K7 mate
This is not the simplest Descriptive notation possible, since sometimes you don't need to specify which Knight file was moved to (as in,
Q-KKt4 could be written as
Q-Kt4 since the move
Q-QKt4 is impossible.) The move
BxP is ambiguous (which pawn: should be
BxQKtP), but Mr Short doesn't care about that too much.
You may consider these your test cases.
Note: I wrote these by hand. If you catch any glaring mistakes, please let me know.
Rules and Scoring
- Standard rules apply : program with output to stdout, or function. Nothing to stderr. Standard loopholes are forbidden.
- Please link to a site where we can test your code.
- Code golf: shortest code wins.
This is my first challenge, so I probably made some noobish errors. Feedback on the question (in the comments, obviously) is appreciated.