Problem Statement
The Forsythe Edwards Notation, FEN, is a compact way of representing where on the chess board the pieces are standing (this is called a chess position) in a single line. Each piece is represented with a letter, which is either 'p' (pawn), 'n' (knight), 'b' (bishop), 'r' (rook), 'q' (queen) or 'k' (king). White pieces have upper case and black pieces lower case letters. Empty squares are represented with a digit, '1'-'8', telling how many consecutive empty squares there are before the next piece on the same line (or the end of the line, whichever comes first). Each line in the chess position is processed from left to right. The lines should be separated with a slash, '/', in FEN.
For instance, consider the chess position below to the left. Periods, '.', are used to represent empty squares, the other letters have the same meaning as specified above. To the right is the FEN for the same position, for clarity split into several lines and without the separating slash.
..k..... 2k5 .pp....p 1pp4p ...p..p. 3p2p1 .R...... 1R6 ........ 8 .......P 7P PPP.b.PK PPP1b1PK n....... n7
When merging these together, and inserting a slash between the lines, it becomes the desired position in FEN:
2k5/1pp4p/3p2p1/1R6/8/7P/PPP1b1PK/n7
Create a class FEN containing the method notation which takes as input a
Definition
- Class:
- FEN
- Method:
- notation
- Parameters:
- String[]
- Returns:
- String
- Method signature:
- String notation(String[] board)
- (be sure your method is public)
Notes
- The input may not necessarily represent a legal chess position. For instance, one player may have more than one king, or more than 32 pieces or maybe no pieces at all. Pawns can also appear on both the first and last line.
- There should never be two digits directly after each other in the output.
- No periods should appear in the return value.
Constraints
- board will contain exactly 8 elements.
- Each element in board will be exactly 8 characters long.
- Each element in board will only contain the six letters mentioned above (upper or lower case) or a period, '.'.
Examples
{"..k.....", ".pp....p", "...p..p.", ".R......", "........", ".......P", "PPP.b.PK", "n......."}
Returns: "2k5/1pp4p/3p2p1/1R6/8/7P/PPP1b1PK/n7"
This is the example mentioned above.
{"rnbqkbnr", "pppppppp", "........", "........", "........", "........", "PPPPPPPP", "RNBQKBNR"}
Returns: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
This is the start position in chess.
{"........", "........", "........", "........", "........", "........", "........", "........"}
Returns: "8/8/8/8/8/8/8/8"
An empty board is an allowed input.
{"..rq.r..","p..bnppQ",".pn.p...","...pP.k.",".P.P.P..","PN......","......PP","..R..RK."}
Returns: "2rq1r2/p2bnppQ/1pn1p3/3pP1k1/1P1P1P2/PN6/6PP/2R2RK1"
{"......pp",".r......","...q..qn",".....q.N","RP..K...","P.q.R..q","..Q..Rk.","..npp..Q"}
Returns: "6pp/1r6/3q2qn/5q1N/RP2K3/P1q1R2q/2Q2Rk1/2npp2Q"
{".Q..RP..","......r.","........","..n...p.","....k.N.","........","..r....Q","........"}
Returns: "1Q2RP2/6r1/8/2n3p1/4k1N1/8/2r4Q/8"
{".B.Q...R","R..k...k","........","N.....P.",".n......","b....P..",".....b..","........"}
Returns: "1B1Q3R/R2k3k/8/N5P1/1n6/b4P2/5b2/8"
{"B.qkb..r","nqp.KkBP",".p.KqRqp","NqR.Rqk.",".N.B.RP.","rBQ..N.N","B..P..r.",".Rq..R.."}
Returns: "B1qkb2r/nqp1KkBP/1p1KqRqp/NqR1Rqk1/1N1B1RP1/rBQ2N1N/B2P2r1/1Rq2R2"
{"bbB.....","..qQ..k.",".qqB....","Rp.K....","..Bn..B.","...q.k.N","..r.....",".B...R.."}
Returns: "bbB5/2qQ2k1/1qqB4/Rp1K4/2Bn2B1/3q1k1N/2r5/1B3R2"
{"kbrK.pbp","BnKP.P.K","R.N.rbqn","Nk.pB.BN","P.kn.Bkb","Bk.Nk.kr",".BK..BNn","Rqn..QrP"}
Returns: "kbrK1pbp/BnKP1P1K/R1N1rbqn/Nk1pB1BN/P1kn1Bkb/Bk1Nk1kr/1BK2BNn/Rqn2QrP"
{"qp.kQb.n","kN..RQB.","BqRkK.Rb","Q.b...R.","BPQk...k","Rr.q.p.b","..pQK.bn",".RbnP..."}
Returns: "qp1kQb1n/kN2RQB1/BqRkK1Rb/Q1b3R1/BPQk3k/Rr1q1p1b/2pQK1bn/1RbnP3"
{"....k...","kR......","nn...b.Q","..nr....","........",".K..P.N.","....R.n.","....N..."}
Returns: "4k3/kR6/nn3b1Q/2nr4/8/1K2P1N1/4R1n1/4N3"
{"..n.....","..B..R..",".Nk.n.P.","nk.N...q","q..k.B.N","qRb.....","bK......","p.B.q..."}
Returns: "2n5/2B2R2/1Nk1n1P1/nk1N3q/q2k1B1N/qRb5/bK6/p1B1q3"
{".n.b..R.","....rk..","KQB.B...","R.....PK","....q.P.",".bP.....",".....b..","R....n.."}
Returns: "1n1b2R1/4rk2/KQB1B3/R5PK/4q1P1/1bP5/5b2/R4n2"
{"qP..rR.q","k.b...Rn",".p.n..p.","NP..PB..","pr..p.B.","BNNR....","NP.B..R.","Nb...rK."}
Returns: "qP2rR1q/k1b3Rn/1p1n2p1/NP2PB2/pr2p1B1/BNNR4/NP1B2R1/Nb3rK1"
{"R.bb....","..Q..qb.","N...NN.q","..KP....","......nN","r.BpRQ.k",".QNkK..K","kR....K."}
Returns: "R1bb4/2Q2qb1/N3NN1q/2KP4/6nN/r1BpRQ1k/1QNkK2K/kR4K1"
{"Pp..pQ..","...P....",".....K..","N.q...N.",".K...B.r","...Nbk..",".Nqp.N..","r.B.B..n"}
Returns: "Pp2pQ2/3P4/5K2/N1q3N1/1K3B1r/3Nbk2/1Nqp1N2/r1B1B2n"
{"...Qb..K","q..rNKNk",".QR.K...","k.Q.....",".......Q","R...k.K.","Q..r....","r..K...N"}
Returns: "3Qb2K/q2rNKNk/1QR1K3/k1Q5/7Q/R3k1K1/Q2r4/r2K3N"
{"PQ....q.",".qQB...p","Pr..N.RB",".BRn....",".k....n.","R....bpk",".p......","........"}
Returns: "PQ4q1/1qQB3p/Pr2N1RB/1BRn4/1k4n1/R4bpk/1p6/8"
{ "........", "........", "........", "........", "........", "........", "........", "........" }
Returns: "8/8/8/8/8/8/8/8"
{ "rnbqkbnr", "pppppppp", "........", "........", "........", "........", "PPPPPPPP", "RNBQKBNR" }
Returns: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
{ "........", "........", "........", "........", ".p......", "p.......", ".......p", "pppppppp" }
Returns: "8/8/8/8/1p6/p7/7p/pppppppp"
{ "..k.....", ".pp....p", "...p..p.", ".R......", "........", ".......P", "PPP.b.PK", "n......n" }
Returns: "2k5/1pp4p/3p2p1/1R6/8/7P/PPP1b1PK/n6n"
{ "..k.....", ".pp....p", "...p..p.", ".R......", "........", ".......P", "PPP.b.PK", "n......." }
Returns: "2k5/1pp4p/3p2p1/1R6/8/7P/PPP1b1PK/n7"