pub struct Position { /* private fields */ }Expand description
Chess position, including the board, turn, rights, and counters.
Size:
- board: 9 * 8 = 72 bytes
- turn: 1 byte (really 1 bit)
- castle rights: 2 bytes (really 2 bits)
- en passant square: 1 bytes (really 65 options)
- reversible move counter: 4 bytes (modeled as u32, really 1 byte would be enough)
- round counter: 4 bytes (value >=1, u16 or even u8 should be enough, who has 65536 rounds in a game of chess?)
Unpacked, this amounts to 88 bytes (Rust 1.91). Packed it is 84 bytes.
https://lichess.org/@/revoof/blog/adapting-nnue-pytorchs-binary-position-format-for-lichess/cpeeAMeY shows that about 18.7 bytes is enough
Besides size, a goal is also to stick these into SQLite3 (or DuckDB), and make something similar to Chess Query Language (with a less weird syntax…) efficently implementable.
The contents can be split in:
- board
- rights: turn + castle + en passant
- counters
Implementations§
Source§impl Position
impl Position
pub fn id(self) -> Id
pub const fn standard_id(self) -> Id
pub const fn polyglot_id(self) -> Id
pub const fn transposition_id(self, basis: &Basis) -> Id
pub const fn apparent_id(self, basis: &Basis) -> Id
Source§impl Position
Position Move API.
impl Position
Position Move API.
pub fn legal_moves(&self) -> Vec<Move>
pub fn legal_castle_moves(&self) -> Vec<Move>
pub fn pseudo_piece_moves(&self) -> Vec<Move>
pub fn legal_king_moves(&self) -> Vec<Move>
pub fn can_castle(&self, side: Side) -> Option<Move>
Source§impl Position
impl Position
pub const fn board(&self) -> Board
pub const fn turn(&self) -> Player
pub const fn castles(&self) -> Castles
pub const fn en_passant(&self) -> Option<EnPassant>
pub const fn reversible(&self) -> u32
pub const fn round(&self) -> NonZeroU32
pub const fn checkers(&self) -> Bitboard
pub const fn is_check(&self) -> bool
Trait Implementations§
impl Copy for Position
impl Eq for Position
Source§impl Ord for Position
impl Ord for Position
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Position
impl PartialOrd for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnsafeUnpin for Position
impl UnwindSafe for Position
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more