#[repr(u8)]pub enum Square {
Show 65 variants
A1 = 0,
B1 = 1,
C1 = 2,
D1 = 3,
E1 = 4,
F1 = 5,
G1 = 6,
H1 = 7,
A2 = 8,
B2 = 9,
C2 = 10,
D2 = 11,
E2 = 12,
F2 = 13,
G2 = 14,
H2 = 15,
A3 = 16,
B3 = 17,
C3 = 18,
D3 = 19,
E3 = 20,
F3 = 21,
G3 = 22,
H3 = 23,
A4 = 24,
B4 = 25,
C4 = 26,
D4 = 27,
E4 = 28,
F4 = 29,
G4 = 30,
H4 = 31,
A5 = 32,
B5 = 33,
C5 = 34,
D5 = 35,
E5 = 36,
F5 = 37,
G5 = 38,
H5 = 39,
A6 = 40,
B6 = 41,
C6 = 42,
D6 = 43,
E6 = 44,
F6 = 45,
G6 = 46,
H6 = 47,
A7 = 48,
B7 = 49,
C7 = 50,
D7 = 51,
E7 = 52,
F7 = 53,
G7 = 54,
H7 = 55,
A8 = 56,
B8 = 57,
C8 = 58,
D8 = 59,
E8 = 60,
F8 = 61,
G8 = 62,
H8 = 63,
NONE = 64,
}Expand description
A square on a chessboard indexed A1 (0) through H8 (63), plus NONE.
Layout: A1 = 0, B1 = 1, …, H1 = 7, A2 = 8, …, H8 = 63.
Variants§
A1 = 0
B1 = 1
C1 = 2
D1 = 3
E1 = 4
F1 = 5
G1 = 6
H1 = 7
A2 = 8
B2 = 9
C2 = 10
D2 = 11
E2 = 12
F2 = 13
G2 = 14
H2 = 15
A3 = 16
B3 = 17
C3 = 18
D3 = 19
E3 = 20
F3 = 21
G3 = 22
H3 = 23
A4 = 24
B4 = 25
C4 = 26
D4 = 27
E4 = 28
F4 = 29
G4 = 30
H4 = 31
A5 = 32
B5 = 33
C5 = 34
D5 = 35
E5 = 36
F5 = 37
G5 = 38
H5 = 39
A6 = 40
B6 = 41
C6 = 42
D6 = 43
E6 = 44
F6 = 45
G6 = 46
H6 = 47
A7 = 48
B7 = 49
C7 = 50
D7 = 51
E7 = 52
F7 = 53
G7 = 54
H7 = 55
A8 = 56
B8 = 57
C8 = 58
D8 = 59
E8 = 60
F8 = 61
G8 = 62
H8 = 63
NONE = 64
Implementations§
Source§impl Square
impl Square
Sourcepub fn from_index(idx: i8) -> Square
pub fn from_index(idx: i8) -> Square
Construct a Square from its 0–63 index. Returns Square::NONE
for out-of-range values.
Examples found in repository?
examples/pawn_debug.rs (line 43)
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 from_u8(idx: u8) -> Square
pub fn from_u8(idx: u8) -> Square
Construct a Square from its 0–63 index as a u8.
Examples found in repository?
examples/pawn_debug.rs (line 70)
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}Trait Implementations§
impl Copy for Square
impl Eq for Square
Source§impl Ord for Square
impl Ord for Square
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Square
impl PartialOrd for Square
impl StructuralPartialEq for Square
Auto Trait Implementations§
impl Freeze for Square
impl RefUnwindSafe for Square
impl Send for Square
impl Sync for Square
impl Unpin for Square
impl UnsafeUnpin for Square
impl UnwindSafe for Square
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