in reply to [OT] Is It Possible To Serialize A Chess Board In Fewer Than 23 Bytes?
I can see how that would tell you where the white queen is located, but how can you tell where the black queen is located with that? Aren't you missing the 6 bytes for black? That totals 8+8+6+6+1 = 29 bytes
3 bits is not enough to represent the column of a pawn that just "lept" (moved 2 places) because it doesn't leave space to indicate that no pawns just lept. You could address this by distinguishing a "leaping" pawn from a "normal" pawn in the 16 strings of 3 bits.
You didn't mention it, but your approach does handle promotions. (e.g. A player can end up with two Queens.)
Solutions that encode the position of each piece (as opposed to those that encode the type of each piece) don't support promotions (without extreme overhead).
You can save a byte by using a variable-base number.
8 + 8 + ceil( log256( 6^32 * 9 * 2^4 * 2^1 ) ) = 28 bytes
Effectively, this uses the space wasted by using 3 bits to store 6 possible values to store the extra states.
But what if we store one grid instead of two, and encode the colour in the 16 strings?
That's 14 different values, which fits in 4 bits each, or 16 bytes for all the pieces.
This reduces the size to 8 + 16 + 1 = 25 bytes.
With a lot of creativity, it's possible to encode all of the extra state in those four bits.
[Credit: Anonymous user 27050's post on Chess StackExchange.]
(Presence of D vs E indicates the player to move. If a King moves, both rooks of the appropriate colour are marked as can't-be-castled. We know the colour of the pawn that just lept based on the player that has the move.)
This reduces the size to 8 + 16 = 24 bytes.
That's as far as the post on Chess StackExchange went. But we can squeeze a bit more using a variable-base number:
8 + ceil( log256( 6^32 * 2^32 * 9 * 2^4 * 2^1 ) ) = 20 bytes
However, a VBN approach is poorly suited for use as variable-length encoding than the preceding approach.
Many updates. I was afraid the site would stop working again.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [OT] Is It Possible To Serialize A Chess Board In Fewer Than 23 Bytes?
by Limbic~Region (Chancellor) on Mar 10, 2026 at 20:06 UTC | |
|
Re^2: [OT] Is It Possible To Serialize A Chess Board In Fewer Than 23 Bytes?
by ikegami (Patriarch) on Mar 11, 2026 at 00:47 UTC |