pub fn encode_board_as_binary(board: &Board<ChessPiece>) -> Vec<u8> ⓘExpand description
Encodes a simple_chess board into a binary vector representation.
§Arguments
board- A reference to aBoard<ChessPiece>representing the simple_chess board to be encoded.
§Returns
A Vec<u8> where each byte represents two simple_chess pieces on the board. The encoding is such that:
-
The board is traversed from top to bottom, left to right.
-
Each pair of consecutive spaces on the board is encoded into a single byte.
-
The first piece in the pair is stored in the higher 4 bits of the byte, and the second piece in the lower 4 bits.
-
If a space is empty, it is represented by
0b0000. -
If a space has a piece on it, it uses the following table to generate a 4 byte code as
{piece_type}{color}Square State Bit representation Empty 000 Pawn 001 Rook 010 Knight 011 Bishop 100 King 101 Queen 110 Color Bit White 0 Black 1