The Forsyth-Edwards notation (FEN) is a standard notation with which a certain game situation of a chess game can be described. FEN contains all information that is needed to continue a chess game from a certain game situation. The system was developed by David Forsyth — journalist with a Scottish paper — who already popularized it in the 19th century. Steven J. Edwards later expanded the FEN so that it could also be used with computers.

schaakbord
Positioning at the start of a chess game from the white player's point of view. On the bottom row, from left to right, we have: tower (R), knight (N), bishop (B), queen (D) and king (K). On the second row we find the pawns. 

In the first part of FEN (we leave out a few parts of the game situation, for example who's turn it is) the placement of the pieces on the chess board is described from the white player's point of view. The rows are described from top to bottom, and the filling of the fields in each row is described from left to right. According to the Standard Algebraic notation1 (SAN) every chess piece is described with one letter: K = king, Q = queen, R = rook, B = bishop, N = knight, P = pawn. White pieces are indicated with uppercase letters (KQRBNP) and black pieces with a lowercase letter (kqrbnp). Empty fields are indicated with numbers 1 to 8 that indicated the number of consecutive empty fields. A slash (/) is used to separate the rows. 

Assignment

Example

>>> print(fen2grid('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR'))
rnbqkbnr
pppppppp
********
********
********
********
PPPPPPPP
RNBQKBNR
>>> print(fen2grid('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR', '.'))
rnbqkbnr
pppppppp
........
........
....P...
........
PPPP.PPP
RNBQKBNR
>>> print(fen2grid('rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR', '+'))
rnbqkbnr
pp+ppppp
++++++++
++p+++++
++++P+++
++++++++
PPPP+PPP
RNBQKBNR

>>> grid = '''rnbqkbnr
... pppppppp
... ********
... ********
... ********
... ********
... PPPPPPPP
... RNBQKBNR'''
>>> print(grid2fen(grid))
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR

>>> print(grid2fen(fen2grid('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR')))
rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR
>>> print(grid2fen(fen2grid('rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR', '.'), '.'))
rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR
>>> print(grid2fen(fen2grid('rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R', '+'), '+'))
rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R