pub struct Zobrist(pub u64);Expand description
Zobrist is a struct that stores a Zobrist hash value, which is a 64-bit
integer used to uniquely identify a specific board position in chess.
Zobrist hashing is efficient for calculating incremental changes in
chess board positions during moves.
Tuple Fields§
§0: u64Implementations§
Source§impl Zobrist
impl Zobrist
Sourcepub fn hash_piece(&mut self, piece: Piece, square: Square)
pub fn hash_piece(&mut self, piece: Piece, square: Square)
Updates the Zobrist hash to reflect the placement or removal of a piece on a given square. The hash is updated by XOR-ing the current value with a precomputed key for the given piece and square.
Sourcepub fn hash_enpassant(&mut self, square: Square)
pub fn hash_enpassant(&mut self, square: Square)
Updates the Zobrist hash to reflect the en passant square. The hash is updated by XOR-ing the current value with a precomputed key for the en passant square.
Sourcepub fn hash_castle(&mut self, castle: CastleRights)
pub fn hash_castle(&mut self, castle: CastleRights)
Updates the Zobrist hash to reflect changes in the castling rights. The hash is updated by XOR-ing the current value with a precomputed key for the current castling rights.
Sourcepub fn swap_castle_hash(&mut self, old: CastleRights, new: CastleRights)
pub fn swap_castle_hash(&mut self, old: CastleRights, new: CastleRights)
Updates the Zobrist hash by swapping the old castling rights with the new ones.
This function XORs the hash with the Zobrist key corresponding to the old castling rights to remove their contribution from the current hash, and then XORs it again with the Zobrist key for the new castling rights to add their contribution. This ensures that the hash accurately reflects the current castling rights of the position.
Trait Implementations§
Source§impl Display for Zobrist
Formats the Zobrist hash as a hexadecimal string.
impl Display for Zobrist
Formats the Zobrist hash as a hexadecimal string.
This implementation converts the 64-bit internal value into a fixed-length hexadecimal string (16 characters), with leading zeros if necessary.