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: PieceImplementations§
Source§impl StateInfo
impl StateInfo
Sourcepub fn new() -> Self
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
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§
Auto Trait Implementations§
impl Freeze for StateInfo
impl RefUnwindSafe for StateInfo
impl Send for StateInfo
impl Sync for StateInfo
impl Unpin for StateInfo
impl UnsafeUnpin for StateInfo
impl UnwindSafe for StateInfo
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
Mutably borrows from an owned value. Read more