Chess 960 Position Generator

FEN:

What is Chess 960?

Chess 960 is a variant of chess where the starting position is randomized. The pieces are placed on the board in a random order, but the king and rooks are always placed on the same squares. The starting position is called a Fischer Random Chess position.

The rules for how the pieces are placed in Fischer Random Chess are as follows:

1. The king is placed on one of the four central squares (e1, d1, e8, d8).
2. The rooks are placed on the two squares next to the king.
3. The remaining pieces are placed on the remaining squares in any order.
4. The bishops must be on opposite-colored squares.
5. The queens must be on the same-colored squares as the king.
6. The knights must be on opposite-colored squares.

The starting position is determined by a FEN code. The FEN code is a string of 6 parts, separated by a space. The first part is the placement of the pieces on the board. The second part is the active color. The third part is the castling rights. The fourth part is the en passant square. The fifth part is the halfmove clock. The sixth part is the fullmove number.

The placement of the pieces is described by a string of 8 rows, each row is described by a string of 8 squares. Each square is described by a character. The character is either a number, which means that many empty squares are in a row, or a letter, which means that a piece is on that square. The letters are as follows:

P - Pawn
N - Knight
B - Bishop
R - Rook
Q - Queen
K - King
p - Pawn (black)
n - Knight (black)
b - Bishop (black)
r - Rook (black)
q - Queen (black)
k - King (black)