pub struct State {
pub pieces: [u64; 2],
pub kings: u64,
}Expand description
The complete board state using bitboard representation.
This struct stores piece positions for both teams and king status using three 64-bit integers (24 bytes total).
§Fields
pieces[0]: Bitboard of all White piecespieces[1]: Bitboard of all Black pieceskings: Bitboard of all king pieces (subset ofpieces[0] | pieces[1])
§Invariants
pieces[0] & pieces[1] == 0(no square has both colors)kings & (pieces[0] | pieces[1]) == kings(kings must be on a piece)- Each team has at most 16 pieces
Fields§
§pieces: [u64; 2]Bitboard of pieces for each team: pieces[0] = White, pieces[1] = Black.
kings: u64Bitboard of king pieces (men that have been promoted).
Implementations§
Source§impl State
impl State
Sourcepub fn validate(&self)
pub fn validate(&self)
Validates the state invariants in debug builds.
This method uses debug_assert! for performance, so checks are only
performed in debug builds. In release builds, this is a no-op.
§Panics (debug builds only)
Panics if any invariant is violated:
- A square is occupied by both teams
- A king exists on an empty square
- A team has more than 16 pieces
§Note
This does NOT validate that pieces on the promotion row are kings.
During multi-capture sequences, pawns can temporarily be on the promotion
row before being promoted at the end of the sequence. The promotion logic
in generate_pawn_captures_at ensures pawns are promoted when sequences
end on the promotion row.
Trait Implementations§
Source§impl Default for State
impl Default for State
Source§fn default() -> Self
fn default() -> Self
Returns the initial game position.
This is equivalent to State::default().
Source§impl Ord for State
impl Ord for State
Source§impl PartialOrd for State
impl PartialOrd for State
impl Copy for State
impl Eq for State
impl StructuralPartialEq for State
Auto Trait Implementations§
impl Freeze for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnwindSafe for State
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more