in reply to [OT] Is It Possible To Serialize A Chess Board In Fewer Than 23 Bytes?

See Chess StackExchange for a similar question.

I know some chess, but I can't clearly see why you need 8 bytes to represent the positions of white or black pieces, and what additional information there is for white pawn, rook, knight, bishop, king, and queen to fit into 6 bytes. Can you give more details?

Also, there might be a way to serialise the board that is very efficient but not really usable (with each piece positioned, you have one less possible position, which might lead to some bit savings in the early stages of the game, for example).

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
  • Comment on Re: [OT] Is It Possible To Serialize A Chess Board In Fewer Than 23 Bytes?
  • Download Code

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:02 UTC
    choroba,
    I have tried to respond to your post multiple times but apparently the Monastery isn't what it used to be.

    See Chess StackExchange for a similar question.

    Thanks. Apparently prior art is 24 bytes and doesn't include as much information as my 23 bytes BUT my 23 bytes is inadequate as explained by ikegami elsewhere in this thread.

    I can't clearly see why you need 8 bytes to represent the positions of white or black pieces

    You have 64 squares and a maximum of 32 pieces. I am trying to compress that in the smallest possible space possible. I use 8 bytes to tell you which of the 64 squares are occupied by white pieces. This is done using a bitstring where the value is either 0 or 1 (piece there or not). I do the same for the black pieces. Once I have told you which spaces are occupied by white pieces, I no longer need to distinguish between white and black - I can simply tell you what piece is at each position. There are 6 different possibilities (pawn/rook/knight/bishop/queen/king). I can do that using 3 bits since 2^3 = 8. Hopefully that now makes sense.

    Cheers - L~R

      The 24-byte prior art does include all the information you did.