Saturday, May 07, 2016

[kujvfoce] Binary encoding a chess piece

if is_slider then case y of {
0 -> unassigned
1 -> bishop
2 -> rook
3 -> queen -- (queen = bishop | rook)
} else case y of {
0 -> unassigned
1 -> pawn
2 -> knight
3 -> king
}

(Haskell-style pseudocode.)

One more bit for the color of the piece, so 4 bits total.

An empty square could be assigned either of the unassigned codes, perhaps the one the corresponds to all zeroes.

No comments :