| Here is how I would it Board is 8x8, which is 6 bits. 4 piece type (rook, queen, knight, bishop. I will represent others (king and pawn) in a special way) is 2 bits. So 8 bits in total per piece I would not use a bit to represent piece color but instead use a seperator to seperate one player's piece from another. Repeating the same position as the last piece can act as a separator since two pieces can't share same square Kings are special that they must exist, so you don't have to specify their type Pawns are special, most likely you will have 1 pawn (of each color) in one column and they can be on rows 2 to 7, or they can be dead or they can be "irregular" which means the pawn moved to another column and there are two pawns in that column now. This data is 3 bits per pawn so 48 bits in total. After that data you can put position of all irregular pawns (additional 6 bits for each irregular pawn). If a pawn promotes, it is represented as a regular piece (and can be considered dead in this 48 bit pawn data) So a chess state is Pawn data (48 bits)
Irregular pawns (6 bit each but I can't tell how many there can be at max. 8 maybe?)
White king pos (6 bits)
White pieces (6 bits for pos + 2 bits for type \* number of pieces)
Seperator (6 bits)
Black King pos (6 bits)
Black pieces (same as white)
Seperator (6 bits, represents end of data)
I think the worst case scenario is there are 8 promotions which would make it add up 248 bitsIf number of pawns on board is small, it might worth representing them using their full positions and using a bit to decide which representation you picked |
- Whose turn is it
- If the king is in its initial position, whether the king has moved previously (that player can't castle anymore).
- For the pawns, you may need the previous position/move to allow en-passant capturing [1]
The standard specification used for this is the Forsyth–Edwards Notation (FEN). [2] It was invented way earlier than computers, so it was targeting humans / isn't optimized for digital compression, but it at least specifies _almost_ everything that you need to track.
The _almost_ is because to account for the repetition rule [2] you need to track all previous positions. At this point, the problem changes from "how to efficiently store the positions of the pieces in the board" to "how to efficiently store (partial) games", and you are probably better off listing the moves than the board state.
[1] https://en.wikipedia.org/wiki/En_passant
[2] https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notati...
[3] https://en.wikipedia.org/wiki/Threefold_repetition