Module hexe_core::board
[−]
[src]
Various board types.
Board Representation
There are three chess board representations provided. They each have various advantages and disadvantages, which are outlined below:
Bitboard
Mapping: bit-to-Square
Advantages:
-
Throughput—excellent for performing parallel operations on the board:
-
Checking whether a file is empty
-
Generating moves for all pieces
-
Disadvantages:
-
Size—larger overall memory cost:
-
A common compact way of representing all pieces with bitboards is to have 6 ×
Role
bitboards and 2 ×Color
bitboards. This results in (2 + 6) × 8 = 64 bytes used to represent all pieces.This is how
MultiBoard
works. -
Using 12 ×
Piece
bitboards is another representation of the entire chess board. This results in 12 × 8 = 96 bytes used to represent all pieces. -
Operations are often done using 64-bit (8 byte) integers.
-
MultiBoard
Mapping: Color
/Piece
/Role
to Bitboard
Advantages:
-
Lookup—very fast square retrieval:
let board = MultiBoard::STANDARD; let king = board.first(Piece::WhiteKing).unwrap(); println!("White king found at {}", king); for sq in board.bitboard(Color::White) { println!("A white piece at {}", sq); }
Disadvantages:
- Checking—slow to find the piece at a square
PieceMap
Advantages:
-
Latency—great for performing instantaneous operations on the board
- Finding whether a square is empty or otherwise what piece sits on it
-
Size—lower overall memory cost
- Operations usually done with a few bytes
Disadvantages:
-
Size—larger upfront memory cost
- Uses exactly 64 bytes for each square on the board and its piece
Modules
bitboard |
A bitmap chess board representation. |
multi_board |
A bitboard-segmented chess board representation. |
piece_map |
A square to piece mapping for fast square lookups. |
Structs
Bitboard |
A mapping of sixty-four bits to squares of a chess board. |
MultiBoard |
A full chess board, represented as multiple bitboard segments. |
PieceMap |
A mapping of sixty-four squares to pieces. |