Skip to main content

StateInfo

Struct StateInfo 

Source
pub struct StateInfo {
    pub checkers: Bitboard,
    pub pinned: Bitboard,
    pub commoners_count: u32,
    pub them_commoners_count: u32,
    pub castling_rights: u8,
    pub ep_square: Option<Square>,
    pub rule50: u8,
    pub captured_count: u8,
    pub captured: [(Square, Piece); 9],
    pub cap_sq: Option<Square>,
    pub cap_piece: Piece,
}
Expand description

Cached state for a position, used during move generation and legality checks.

Fields are populated by Board::populate_state and consumed by Board::legal and generate_legal.

Fields§

§checkers: Bitboard§pinned: Bitboard§commoners_count: u32§them_commoners_count: u32§castling_rights: u8§ep_square: Option<Square>§rule50: u8§captured_count: u8§captured: [(Square, Piece); 9]§cap_sq: Option<Square>§cap_piece: Piece

Implementations§

Source§

impl StateInfo

Source

pub fn new() -> Self

Create a new StateInfo with all fields zeroed/empty.

Examples found in repository?
examples/perft_divide.rs (line 28)
8fn main() {
9    atomic_movegen::attacks::init();
10    let args: Vec<String> = env::args().collect();
11    if args.len() < 3 {
12        eprintln!("Usage: perft_divide <fen> <depth>");
13        return;
14    }
15    let fen = &args[1];
16    let depth: u32 = args[2].parse().unwrap_or(1);
17
18    let mut board = Board::from_fen(fen).expect("Invalid FEN");
19
20    let mut moves = MoveList::new();
21    movegen::generate_legal(&board, &mut moves);
22    moves
23        .as_mut_slice()
24        .sort_by_key(|m| (m.from_sq() as u16, m.to_sq() as u16));
25
26    let mut total = 0u64;
27    for &m in moves.as_slice() {
28        let mut state = atomic_movegen::board::StateInfo::new();
29        board.do_move(m, &mut state);
30        let cnt = if depth <= 1 {
31            1
32        } else {
33            perft(&mut board, depth - 1)
34        };
35        board.undo_move(m, &state);
36        total += cnt;
37        println!("{}{}: {}", sq_str(m.from_sq()), sq_str(m.to_sq()), cnt);
38    }
39    println!("\nNodes searched: {}", total);
40}
More examples
Hide additional examples
examples/fen_after.rs (line 27)
8fn main() {
9    atomic_movegen::attacks::init();
10    let args: Vec<String> = env::args().collect();
11    if args.len() < 3 {
12        eprintln!("Usage: fen_after <fen> <move>");
13        return;
14    }
15    let fen = &args[1];
16    let movestr = &args[2];
17    let mut board = Board::from_fen(fen).expect("Invalid FEN");
18
19    let from_sq = parse_sq(&movestr[0..2]);
20    let to_sq = parse_sq(&movestr[2..4]);
21
22    let mut moves = MoveList::new();
23    movegen::generate_legal(&board, &mut moves);
24
25    for &m in moves.as_slice() {
26        if m.from_sq() == from_sq && m.to_sq() == to_sq {
27            let mut state = atomic_movegen::board::StateInfo::new();
28            board.do_move(m, &mut state);
29            println!("{}", board.fen());
30
31            let mut moves2 = MoveList::new();
32            movegen::generate_legal(&board, &mut moves2);
33            moves2
34                .as_mut_slice()
35                .sort_by_key(|m| (m.from_sq() as u16, m.to_sq() as u16));
36            println!("Legal moves ({} total):", moves2.len());
37            for &m2 in moves2.as_slice() {
38                println!("  {}{}", sq_str(m2.from_sq()), sq_str(m2.to_sq()));
39            }
40            return;
41        }
42    }
43    println!("Move not found");
44}

Trait Implementations§

Source§

impl Clone for StateInfo

Source§

fn clone(&self) -> StateInfo

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for StateInfo

Source§

impl Debug for StateInfo

Source§

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

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

impl Default for StateInfo

Source§

fn default() -> Self

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.