Fischer random chess, also known as Chess960 for the 960 valid starting boards, is a variant of chess where each player's pieces are randomly shuffled at the start. As a reminder, each player gets 8 pawns, two rooks, two knights, two bishops, one queen, and one king. For this challenge, you don't need to know anything about the rules of chess, as we are only concerned with the starting positions of the pieces on a 8x8 chessboard. In particular, white's non-pawn pieces are placed randomly on the first rank (row of the chessboard). The white pawns are placed on the second rank as usual. In addition, the following rules for white's non-pawn pieces must be adhered to:
- The bishops must be placed on opposite color squares (since the chessboard has a checkerboard pattern, that means there is an odd distance between them)
- The king must be placed on a square between the rooks
Black's pieces are placed mirroring white's horizontally on the board, so that black's pieces are on the same file (column) as the corresponding white's pieces.
The input board must be given as a FEN board string, which is standard for chess programs. From the FEN specification:
The board contents are specified starting with the eighth rank and ending with the first rank. For each rank, the squares are specified from file a to file h. White pieces are identified by uppercase SAN piece letters ("PNBRQK") and black pieces are identified by lowercase SAN piece letters ("pnbrqk"). Empty squares are represented by the digits one through eight; the digit used represents the count of contiguous empty squares along a rank. A solidus character "/" is used to separate data of adjacent ranks.
For reference, SAN piece letters are: pawn = "P", knight = "N", bishop = "B", rook = "R", queen = "Q", and king = "K". White's pieces are in uppercase while black's are in lowercase.
Given a valid FEN board string, described above, output a boolean value for whether or not the input board is a Fischer random chess starting board.
The first string is a standard board (fun fact: board 518 in the standard Fischer random chess numbering scheme).
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR rqkbbrnn/pppppppp/8/8/8/8/PPPPPPPP/RQKBBRNN bqrnnkrb/pppppppp/8/8/8/8/PPPPPPPP/BQRNNKRB nrbbqnkr/pppppppp/8/8/8/8/PPPPPPPP/NRBBQNKR bqnrnkrb/pppppppp/8/8/8/8/PPPPPPPP/BQNRNKRB nnqrkrbb/pppppppp/8/8/8/8/PPPPPPPP/NNQRKRBB nnbrkqrb/pppppppp/8/8/8/8/PPPPPPPP/NNBRKQRB nbbrnkqr/pppppppp/8/8/8/8/PPPPPPPP/NBBRNKQR rknrnbbq/pppppppp/8/8/8/8/PPPPPPPP/RKNRNBBQ qnbbrknr/pppppppp/8/8/8/8/PPPPPPPP/QNBBRKNR
Everything after the board string starting with
# is a comment for compactness and is not part of the input.
8/8/8/8/8/8/8/8 # Empty board 8/8/8/8/8/8/PPPPPPPP/RNBQKBNR # Missing black's pieces RNBQKBNR/PPPPPPPP/8/8/8/8/PPPPPPPP/RNBQKBNR # Missing black's pieces and too many white pieces rnbqkbnr/ppp1pppp/8/8/8/8/PPPPPPPP/RNBQKBNR # Missing pawn rnbkqbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR # Black's pieces don't mirror white's rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR # Not a starting board 4q2k/2r1r3/4PR1p/p1p5/P1Bp1Q1P/1P6/6P1/6K1 # Definitely not a starting board rkbqnnbr/pppppppp/8/8/8/8/PPPPPPPP/RKBQNNBR # Bishops must be on opposite squares qkrnbbrn/pppppppp/8/8/8/8/PPPPPPPP/QKRNBBRN # King must be between rooks rkrbbnnn/pppppppp/8/8/8/8/PPPPPPPP/RKRBBNNN # Missing queens