encode_board_as_binary

Function encode_board_as_binary 

Source
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 a Board<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 StateBit representation
    Empty000
    Pawn001
    Rook010
    Knight011
    Bishop100
    King101
    Queen110
    ColorBit
    White0
    Black1