9
0
In chess, Forsyth-Edwards Notation, more commonly called "FEN", is a textual way of transcribing boards. It describes each of the board's eight rows (called "ranks" in chess) from top to bottom from White's perspective. The pieces are written as K (king), Q (queen), R (rook), B (bishop), N (knight), and P (pawn). Black pieces use these letters in lowercase, and white pieces use these letters in uppercase. Empty spaces are indicated by a number from 1 to 8 indicating how many consecutive empty spaces there are. A completely empty rank would be 8
, a single black rook in the rightmost column (called "files" in chess) would be 7r
, and two white pawns on each end of a row would be PP4PP
. Ranks are separated by a /
. There is normally other information added, indicating which side is to move, castling and en passant rights, move number, and halfmove clock, but we will ignore them for the purposes of this challenge.
Input
A FEN string, from the command line or STDIN, as you please. You may assume that this string is always valid.
Output
Write to STDOUT a simple ASCII art representation of the board as it would actually appear:
- Pieces are represented by their character in FEN
- Empty squares are represented by spaces
- Pieces and squares are separated by a pipe
|
and there are pipes on each side of the board
So an empty board, written as 8/8/8/8/8/8/8/8
in FEN, would appear as
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
The starting position of a chess game is written as rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
, and would appear as
|r|n|b|q|k|b|n|r|
|p|p|p|p|p|p|p|p|
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
|P|P|P|P|P|P|P|P|
|R|N|B|Q|K|B|N|R|
The final position of Anderssen-Kieseritzky 1851, called "The Immortal Game" in the chess community, is written as r1bk3r/p2pBpNp/n4n2/1p1NP2P/6P1/3P4/P1P1K3/q5b1
, and your program when fed that input would output:
|r| |b|k| | | |r|
|p| | |p|B|p|N|p|
|n| | | | |n| | |
| |p| |N|P| | |P|
| | | | | | |P| |
| | | |P| | | | |
|P| |P| |K| | | |
|q| | | | | |b| |
Is it acceptable to write a function which takes input and returns output, rather than writing it to STDOUT? – Fund Monica's Lawsuit – 2016-04-24T19:09:39.877
@QPaysTaxes By default we allow it and indeed several solutions do that already. Ultimately it's up to the OP though it seems unnecessary to override our defaults in this case. – Alex A. – 2016-04-24T21:19:20.443
2The answer you accepted is not the shortest one. Regardless of your feelings towards golfing languages, code golf means that the shortest code wins. – Dennis – 2016-04-25T00:21:25.427
@Dennis If I cannot exclude golfing languages from the challenge outright, I will exclude them from the winner's circle. Users may vote for the golfing language winner as they please and scroll down to see it.
– EMBLEM – 2016-04-25T01:16:28.5933
You also cannot penalize them or accept an arbitrary answer. The whole site is built around objective winning criteria.
– Dennis – 2016-04-25T01:33:52.013@Dennis I have removed my votes from all answers from which I could remove them and removed the accept of the Perl answer. I will not, however, accept an answer to this question unless that is also required. – EMBLEM – 2016-04-25T01:59:16.673
No, that's not required. Many challenges do not have accepted answers. – Dennis – 2016-04-25T04:38:43.903
1
+1
for an interesting challenge.-2
for accepting the wrong answer for no good reason – James – 2016-06-20T19:15:51.453