pub struct Bitboard(pub u64);Expand description
Tuple Fields§
§0: u64Implementations§
Source§impl Bitboard
impl Bitboard
Sourcepub fn is_empty(self) -> bool
pub fn is_empty(self) -> bool
Returns true if no squares are set.
Examples found in repository?
examples/pawn_debug.rs (line 27)
7fn main() {
8 atomic_movegen::attacks::init();
9 let args: Vec<String> = env::args().collect();
10 if args.len() < 2 {
11 eprintln!("Usage: pawn_debug <fen>");
12 return;
13 }
14 let fen = &args[1];
15 let board = Board::from_fen(fen).expect("Invalid FEN");
16
17 println!("Board side to move: {:?}", board.side_to_move());
18
19 // Manual check: iterate all pawns
20 let us = board.side_to_move();
21 let _them = us.flip();
22 let _occupied = board.occupied();
23
24 let pawns = board.pieces_color_pt(us, PieceType::Pawn);
25 println!("Pawns ({:?}): {}", us, pawns.count());
26 let mut p = pawns;
27 while !p.is_empty() {
28 let sq = p.pop_lsb();
29 println!(
30 " Pawn at {} (idx={}): file={} rank={}",
31 sq_str(sq),
32 sq as u8,
33 file_of(sq) as u8,
34 rank_of(sq) as u8
35 );
36 }
37
38 // Check what generate_legal produces
39 let mut moves = MoveList::new();
40 movegen::generate_legal(&board, &mut moves);
41
42 // Find all h3g2 moves
43 let h3 = Square::from_index(23);
44 let g2 = Square::from_index(14);
45 println!("\nAll h3g2 moves:");
46 for (i, &m) in moves.as_slice().iter().enumerate() {
47 if m.from_sq() == h3 && m.to_sq() == g2 {
48 println!(
49 " Move #{}: from={} to={} type={:?}",
50 i,
51 sq_str(m.from_sq()),
52 sq_str(m.to_sq()),
53 m.move_type()
54 );
55 }
56 }
57
58 // Also check how many times each move appears
59 use std::collections::HashMap;
60 let mut counts: HashMap<(u16, u16, u16), usize> = HashMap::new();
61 for &m in moves.as_slice() {
62 *counts
63 .entry((m.from_sq() as u16, m.to_sq() as u16, m.move_type() as u16))
64 .or_insert(0) += 1;
65 }
66 for ((from, to, mt), count) in &counts {
67 if *count > 1 {
68 println!(
69 "DUPLICATE: {}{} type={:?} appears {} times",
70 sq_str(Square::from_u8(*from as u8)),
71 sq_str(Square::from_u8(*to as u8)),
72 match mt {
73 0 => "Normal",
74 1 => "Promo",
75 2 => "EP",
76 3 => "Castle",
77 _ => "?",
78 },
79 count
80 );
81 }
82 }
83}Sourcepub fn count(self) -> u32
pub fn count(self) -> u32
Return the number of squares set in the bitboard.
Examples found in repository?
examples/pawn_debug.rs (line 25)
7fn main() {
8 atomic_movegen::attacks::init();
9 let args: Vec<String> = env::args().collect();
10 if args.len() < 2 {
11 eprintln!("Usage: pawn_debug <fen>");
12 return;
13 }
14 let fen = &args[1];
15 let board = Board::from_fen(fen).expect("Invalid FEN");
16
17 println!("Board side to move: {:?}", board.side_to_move());
18
19 // Manual check: iterate all pawns
20 let us = board.side_to_move();
21 let _them = us.flip();
22 let _occupied = board.occupied();
23
24 let pawns = board.pieces_color_pt(us, PieceType::Pawn);
25 println!("Pawns ({:?}): {}", us, pawns.count());
26 let mut p = pawns;
27 while !p.is_empty() {
28 let sq = p.pop_lsb();
29 println!(
30 " Pawn at {} (idx={}): file={} rank={}",
31 sq_str(sq),
32 sq as u8,
33 file_of(sq) as u8,
34 rank_of(sq) as u8
35 );
36 }
37
38 // Check what generate_legal produces
39 let mut moves = MoveList::new();
40 movegen::generate_legal(&board, &mut moves);
41
42 // Find all h3g2 moves
43 let h3 = Square::from_index(23);
44 let g2 = Square::from_index(14);
45 println!("\nAll h3g2 moves:");
46 for (i, &m) in moves.as_slice().iter().enumerate() {
47 if m.from_sq() == h3 && m.to_sq() == g2 {
48 println!(
49 " Move #{}: from={} to={} type={:?}",
50 i,
51 sq_str(m.from_sq()),
52 sq_str(m.to_sq()),
53 m.move_type()
54 );
55 }
56 }
57
58 // Also check how many times each move appears
59 use std::collections::HashMap;
60 let mut counts: HashMap<(u16, u16, u16), usize> = HashMap::new();
61 for &m in moves.as_slice() {
62 *counts
63 .entry((m.from_sq() as u16, m.to_sq() as u16, m.move_type() as u16))
64 .or_insert(0) += 1;
65 }
66 for ((from, to, mt), count) in &counts {
67 if *count > 1 {
68 println!(
69 "DUPLICATE: {}{} type={:?} appears {} times",
70 sq_str(Square::from_u8(*from as u8)),
71 sq_str(Square::from_u8(*to as u8)),
72 match mt {
73 0 => "Normal",
74 1 => "Promo",
75 2 => "EP",
76 3 => "Castle",
77 _ => "?",
78 },
79 count
80 );
81 }
82 }
83}Sourcepub fn lsb(self) -> Square
pub fn lsb(self) -> Square
Return the least-significant (lowest-index) set square.
§Panics
Panics in debug mode if the bitboard is empty.
Sourcepub fn pop_lsb(&mut self) -> Square
pub fn pop_lsb(&mut self) -> Square
Extract and remove the least-significant set square.
Examples found in repository?
examples/pawn_debug.rs (line 28)
7fn main() {
8 atomic_movegen::attacks::init();
9 let args: Vec<String> = env::args().collect();
10 if args.len() < 2 {
11 eprintln!("Usage: pawn_debug <fen>");
12 return;
13 }
14 let fen = &args[1];
15 let board = Board::from_fen(fen).expect("Invalid FEN");
16
17 println!("Board side to move: {:?}", board.side_to_move());
18
19 // Manual check: iterate all pawns
20 let us = board.side_to_move();
21 let _them = us.flip();
22 let _occupied = board.occupied();
23
24 let pawns = board.pieces_color_pt(us, PieceType::Pawn);
25 println!("Pawns ({:?}): {}", us, pawns.count());
26 let mut p = pawns;
27 while !p.is_empty() {
28 let sq = p.pop_lsb();
29 println!(
30 " Pawn at {} (idx={}): file={} rank={}",
31 sq_str(sq),
32 sq as u8,
33 file_of(sq) as u8,
34 rank_of(sq) as u8
35 );
36 }
37
38 // Check what generate_legal produces
39 let mut moves = MoveList::new();
40 movegen::generate_legal(&board, &mut moves);
41
42 // Find all h3g2 moves
43 let h3 = Square::from_index(23);
44 let g2 = Square::from_index(14);
45 println!("\nAll h3g2 moves:");
46 for (i, &m) in moves.as_slice().iter().enumerate() {
47 if m.from_sq() == h3 && m.to_sq() == g2 {
48 println!(
49 " Move #{}: from={} to={} type={:?}",
50 i,
51 sq_str(m.from_sq()),
52 sq_str(m.to_sq()),
53 m.move_type()
54 );
55 }
56 }
57
58 // Also check how many times each move appears
59 use std::collections::HashMap;
60 let mut counts: HashMap<(u16, u16, u16), usize> = HashMap::new();
61 for &m in moves.as_slice() {
62 *counts
63 .entry((m.from_sq() as u16, m.to_sq() as u16, m.move_type() as u16))
64 .or_insert(0) += 1;
65 }
66 for ((from, to, mt), count) in &counts {
67 if *count > 1 {
68 println!(
69 "DUPLICATE: {}{} type={:?} appears {} times",
70 sq_str(Square::from_u8(*from as u8)),
71 sq_str(Square::from_u8(*to as u8)),
72 match mt {
73 0 => "Normal",
74 1 => "Promo",
75 2 => "EP",
76 3 => "Castle",
77 _ => "?",
78 },
79 count
80 );
81 }
82 }
83}Sourcepub fn more_than_one(self) -> bool
pub fn more_than_one(self) -> bool
Returns true if more than one square is set.
Trait Implementations§
impl Copy for Bitboard
impl Eq for Bitboard
impl StructuralPartialEq for Bitboard
Auto Trait Implementations§
impl Freeze for Bitboard
impl RefUnwindSafe for Bitboard
impl Send for Bitboard
impl Sync for Bitboard
impl Unpin for Bitboard
impl UnsafeUnpin for Bitboard
impl UnwindSafe for Bitboard
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