Quadboard
A type-safe SIMD implementation of the quadboard data structure, originally written as part of the konig engine.
The stability of this crate is contingent on the stability of the portable_simd feature (tracking issue #86656), though in the interim this could be worked around with cargo flags.
Usage
Suppose you want to use a quadboard to represent a chessboard state in the usual way, with pieces defined as follows:
This particular encoding can be used to fit a piece into a nibble by just taking the bitwise AND of its fields, so we can define the following encoding:
// going from a Piece to a Nibble is fairly simple
// in reverse, we have a few more problems to deal with:
// 1. 0b0111 and 0b1111 don't correpond to specific pieces, and;
// 2. 0b1000 and 0b0000 map to the same piece.
//
// these are details that should encourage you to use a different
// encoding scheme –– there's surprising room for improvement
And that's it! This is the minimum required to use a Quadboard<Piece>, mostly with the get and set methods as well as their unsafe _unchecked equivalents.
// create a quadboard filled with Piece::default()
let mut qb = default;
// insert some pieces
qb.set;
qb.set;
qb.set;
qb.set;
// and read them out
assert_eq!
// a quadboard is defined at all indices at all times
assert_eq!