Enum cozy_chess::Square
source · pub enum Square {
Show 64 variants
A1,
B1,
C1,
D1,
E1,
F1,
G1,
H1,
A2,
B2,
C2,
D2,
E2,
F2,
G2,
H2,
A3,
B3,
C3,
D3,
E3,
F3,
G3,
H3,
A4,
B4,
C4,
D4,
E4,
F4,
G4,
H4,
A5,
B5,
C5,
D5,
E5,
F5,
G5,
H5,
A6,
B6,
C6,
D6,
E6,
F6,
G6,
H6,
A7,
B7,
C7,
D7,
E7,
F7,
G7,
H7,
A8,
B8,
C8,
D8,
E8,
F8,
G8,
H8,
}
Expand description
A square on a chessboard. Squares are ordered in rank-major order (A1, B1, C1, … H8).
Variants§
A1
The A1 square.
B1
The B1 square.
C1
The C1 square.
D1
The D1 square.
E1
The E1 square.
F1
The F1 square.
G1
The G1 square.
H1
The H1 square.
A2
The A2 square.
B2
The B2 square.
C2
The C2 square.
D2
The D2 square.
E2
The E2 square.
F2
The F2 square.
G2
The G2 square.
H2
The H2 square.
A3
The A3 square.
B3
The B3 square.
C3
The C3 square.
D3
The D3 square.
E3
The E3 square.
F3
The F3 square.
G3
The G3 square.
H3
The H3 square.
A4
The A4 square.
B4
The B4 square.
C4
The C4 square.
D4
The D4 square.
E4
The E4 square.
F4
The F4 square.
G4
The G4 square.
H4
The H4 square.
A5
The A5 square.
B5
The B5 square.
C5
The C5 square.
D5
The D5 square.
E5
The E5 square.
F5
The F5 square.
G5
The G5 square.
H5
The H5 square.
A6
The A6 square.
B6
The B6 square.
C6
The C6 square.
D6
The D6 square.
E6
The E6 square.
F6
The F6 square.
G6
The G6 square.
H6
The H6 square.
A7
The A7 square.
B7
The B7 square.
C7
The C7 square.
D7
The D7 square.
E7
The E7 square.
F7
The F7 square.
G7
The G7 square.
H7
The H7 square.
A8
The A8 square.
B8
The B8 square.
C8
The C8 square.
D8
The D8 square.
E8
The E8 square.
F8
The F8 square.
G8
The G8 square.
H8
The H8 square.
Implementations§
source§impl Square
impl Square
source§impl Square
impl Square
sourcepub const fn new(file: File, rank: Rank) -> Square
pub const fn new(file: File, rank: Rank) -> Square
Make a square from a file and a rank.
§Examples
assert_eq!(Square::new(File::A, Rank::First), Square::A1);
sourcepub const fn bitboard(self) -> BitBoard
pub const fn bitboard(self) -> BitBoard
Get a bitboard with this square set.
assert_eq!(Square::B2.bitboard(), bitboard! {
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. X . . . . . .
. . . . . . . .
});
sourcepub const fn offset(self, file_offset: i8, rank_offset: i8) -> Square
pub const fn offset(self, file_offset: i8, rank_offset: i8) -> Square
Offsets the square towards the top right.
§Panics
Panic if the offset would put the square out of bounds.
See Square::try_offset
for a non-panicking variant.
§Examples
assert_eq!(Square::A1.offset(1, 2), Square::B3);
sourcepub const fn relative_to(self, color: Color) -> Square
pub const fn relative_to(self, color: Color) -> Square
Get a square relative to some color. This flips the square if viewing from black’s perspective.
§Examples
assert_eq!(Square::A1.relative_to(Color::White), Square::A1);
assert_eq!(Square::A1.relative_to(Color::Black), Square::A8);
Trait Implementations§
source§impl FromIterator<Square> for BitBoard
impl FromIterator<Square> for BitBoard
source§impl Ord for Square
impl Ord for Square
source§impl PartialEq for Square
impl PartialEq for Square
source§impl PartialOrd for Square
impl PartialOrd for Square
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more