pub struct Zobrist<P, V: ZobristValue> { /* private fields */ }
Expand description
A wrapper for Position
that maintains an incremental Zobrist hash.
Examples
use shakmaty::{Chess, Position, Move, Square, Role, zobrist::Zobrist};
let pos: Zobrist<Chess, u64> = Zobrist::default();
assert_eq!(pos.zobrist_hash(), 0x463b96181691fc9c);
assert_eq!(pos.zobrist_hash(), 0x463b96181691fc9c); // cached
// 1. e4
let pos = pos.play(&Move::Normal {
role: Role::Pawn,
from: Square::E2,
to: Square::E4,
capture: None,
promotion: None,
})?;
// Incrementally updated (or recomputed from scratch if incremental
// updates not supported).
assert_eq!(pos.zobrist_hash(), 0x823c9b50fd114196);
Implementations
sourceimpl<P, V: ZobristValue> Zobrist<P, V>
impl<P, V: ZobristValue> Zobrist<P, V>
sourceimpl<P: ZobristHash, V: ZobristValue> Zobrist<P, V>
impl<P: ZobristHash, V: ZobristValue> Zobrist<P, V>
pub fn zobrist_hash(&self) -> V
Trait Implementations
sourceimpl<P: Default, V: ZobristValue> Default for Zobrist<P, V>
impl<P: Default, V: ZobristValue> Default for Zobrist<P, V>
sourceimpl<P: FromSetup + Position, V: ZobristValue> FromSetup for Zobrist<P, V>
impl<P: FromSetup + Position, V: ZobristValue> FromSetup for Zobrist<P, V>
sourcefn from_setup(
setup: Setup,
mode: CastlingMode
) -> Result<Self, PositionError<Self>>
fn from_setup(
setup: Setup,
mode: CastlingMode
) -> Result<Self, PositionError<Self>>
sourceimpl<P: Position + ZobristHash, V: ZobristValue> Position for Zobrist<P, V>
impl<P: Position + ZobristHash, V: ZobristValue> Position for Zobrist<P, V>
sourcefn maybe_ep_square(&self) -> Option<Square>
fn maybe_ep_square(&self) -> Option<Square>
Unconditionally gets the en passant target square after a double pawn push, even if no en passant capture is actually possible. Read more
sourcefn remaining_checks(&self) -> Option<&ByColor<RemainingChecks>>
fn remaining_checks(&self) -> Option<&ByColor<RemainingChecks>>
Remaining checks in Three-Check.
sourcefn halfmoves(&self) -> u32
fn halfmoves(&self) -> u32
Number of half-moves since the last capture or pawn move. Read more
sourcefn fullmoves(&self) -> NonZeroU32
fn fullmoves(&self) -> NonZeroU32
Move number. Starts at 1 and is increased after every black move.
sourcefn into_setup(self, mode: EnPassantMode) -> Setup
fn into_setup(self, mode: EnPassantMode) -> Setup
Converts the position to the current Setup
.
sourcefn legal_moves(&self) -> MoveList
fn legal_moves(&self) -> MoveList
Generates all legal moves.
sourcefn san_candidates(&self, role: Role, to: Square) -> MoveList
fn san_candidates(&self, role: Role, to: Square) -> MoveList
Generates a subset of legal moves: All piece moves and drops of type
role
to the square to
, excluding castling moves. Read more
sourcefn castling_moves(&self, side: CastlingSide) -> MoveList
fn castling_moves(&self, side: CastlingSide) -> MoveList
Generates legal castling moves.
sourcefn en_passant_moves(&self) -> MoveList
fn en_passant_moves(&self) -> MoveList
Generates en passant moves.
sourcefn capture_moves(&self) -> MoveList
fn capture_moves(&self) -> MoveList
Generates capture moves.
sourcefn promotion_moves(&self) -> MoveList
fn promotion_moves(&self) -> MoveList
Generate promotion moves.
sourcefn is_irreversible(&self, m: &Move) -> bool
fn is_irreversible(&self, m: &Move) -> bool
Tests if a move is irreversible. Read more
sourcefn king_attackers(
&self,
square: Square,
attacker: Color,
occupied: Bitboard
) -> Bitboard
fn king_attackers(
&self,
square: Square,
attacker: Color,
occupied: Bitboard
) -> Bitboard
Attacks that a king on square
would have to deal with.
sourcefn is_variant_end(&self) -> bool
fn is_variant_end(&self) -> bool
Checks if the game is over due to a special variant end condition. Read more
sourcefn has_insufficient_material(&self, color: Color) -> bool
fn has_insufficient_material(&self, color: Color) -> bool
Tests if a side has insufficient winning material. Read more
sourcefn variant_outcome(&self) -> Option<Outcome>
fn variant_outcome(&self) -> Option<Outcome>
Tests special variant winning, losing and drawing conditions.
sourcefn play_unchecked(&mut self, m: &Move)
fn play_unchecked(&mut self, m: &Move)
Plays a move. It is the callers responsibility to ensure the move is legal. Read more
sourcefn our(&self, role: Role) -> Bitboard
fn our(&self, role: Role) -> Bitboard
Squares occupied with the given piece type by the side to move.
sourcefn their(&self, role: Role) -> Bitboard
fn their(&self, role: Role) -> Bitboard
Squares occupied with the given piece type by the opponent of the side to move. Read more
sourcefn pseudo_legal_ep_square(&self) -> Option<Square>
fn pseudo_legal_ep_square(&self) -> Option<Square>
The en passant square, if it is the target of a pseudo-legal en passant move. Read more
sourcefn legal_ep_square(&self) -> Option<Square>
fn legal_ep_square(&self) -> Option<Square>
sourcefn ep_square(&self, mode: EnPassantMode) -> Option<Square>
fn ep_square(&self, mode: EnPassantMode) -> Option<Square>
The en passant square.
sourcefn is_checkmate(&self) -> bool
fn is_checkmate(&self) -> bool
Tests for checkmate.
sourcefn is_stalemate(&self) -> bool
fn is_stalemate(&self) -> bool
Tests for stalemate.
sourcefn is_insufficient_material(&self) -> bool
fn is_insufficient_material(&self) -> bool
Tests if both sides have insufficient winning material. Read more
sourcefn is_game_over(&self) -> bool
fn is_game_over(&self) -> bool
Tests if the game is over due to checkmate, stalemate, insufficient material or variant end. Read more
Auto Trait Implementations
impl<P, V> !RefUnwindSafe for Zobrist<P, V>
impl<P, V> Send for Zobrist<P, V> where
P: Send,
V: Send,
impl<P, V> !Sync for Zobrist<P, V>
impl<P, V> Unpin for Zobrist<P, V> where
P: Unpin,
V: Unpin,
impl<P, V> UnwindSafe for Zobrist<P, V> where
P: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more