Skip to main content

Square

Enum Square 

Source
#[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

Source

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}
Source

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§

Source§

impl Add<Direction> for Square

Source§

type Output = Square

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Direction) -> Square

Performs the + operation. Read more
Source§

impl BitAnd for Square

Source§

type Output = Bitboard

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Square) -> Bitboard

Performs the & operation. Read more
Source§

impl BitAnd<Square> for Bitboard

Source§

type Output = Bitboard

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Square) -> Bitboard

Performs the & operation. Read more
Source§

impl BitOr for Square

Source§

type Output = Bitboard

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Square) -> Bitboard

Performs the | operation. Read more
Source§

impl BitOr<Square> for Bitboard

Source§

type Output = Bitboard

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Square) -> Bitboard

Performs the | operation. Read more
Source§

impl BitXor<Square> for Bitboard

Source§

type Output = Bitboard

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Square) -> Bitboard

Performs the ^ operation. Read more
Source§

impl Clone for Square

Source§

fn clone(&self) -> Square

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 Square

Source§

impl Debug for Square

Source§

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

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

impl Eq for Square

Source§

impl Hash for Square

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Square

Source§

fn cmp(&self, other: &Square) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Square

Source§

fn eq(&self, other: &Square) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Square

Source§

fn partial_cmp(&self, other: &Square) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Square

Source§

impl Sub<Direction> for Square

Source§

type Output = Square

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Direction) -> Square

Performs the - operation. Read more
Source§

impl Sub<Square> for Bitboard

Source§

type Output = Bitboard

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Square) -> Bitboard

Performs the - operation. 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.