Skip to main content

Zobrist

Struct Zobrist 

Source
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: u64

Implementations§

Source§

impl Zobrist

Source

pub const fn null() -> Self

Creates a Zobrist instance with a hash value of zero.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn hash_side(&mut self)

Updates the Zobrist hash to reflect a change in the side to move. The hash is updated by XOR-ing the current value with a predefined key for the side.

Trait Implementations§

Source§

impl Clone for Zobrist

Source§

fn clone(&self) -> Zobrist

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Zobrist

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Zobrist

Source§

fn default() -> Zobrist

Returns the “default value” for a type. Read more
Source§

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.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Zobrist

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Zobrist

Source§

fn eq(&self, other: &Zobrist) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Zobrist

Source§

fn partial_cmp(&self, other: &Zobrist) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Zobrist

Source§

impl Eq for Zobrist

Source§

impl StructuralPartialEq for Zobrist

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.