Enum hexe_core::square::Square
[−]
[src]
#[repr(u8)]pub enum Square { 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, }
A square on a chess board.
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
Methods
impl Square
[src]
pub fn new(file: File, rank: Rank) -> Square
[src]
Initializes a Square
from a File
and Rank
.
Examples
Basic usage:
let s = Square::new(File::B, Rank::Five); assert_eq!(s.file(), File::B); assert_eq!(s.rank(), Rank::Five);
pub fn file(self) -> File
[src]
Returns the File
for self
.
pub fn rank(self) -> Rank
[src]
Returns the Rank
for self
.
pub fn rev_file(self) -> Square
[src]
pub fn rev_rank(self) -> Square
[src]
pub fn combine(self, other: Square) -> Square
[src]
Combines the file of self
with the rank of other
.
Examples
Basic usage:
let s1 = Square::B5; let s2 = Square::C7; assert_eq!(s1.combine(s2), Square::B7); assert_eq!(s2.combine(s1), Square::C5);
pub fn color(self) -> Color
[src]
Returns the Color
for self
.
Examples
Basic usage:
let a = Square::A1; assert_eq!(a.color(), Color::Black); let b = Square::B5; assert_eq!(b.color(), Color::White);
pub fn color_eq(self, other: Square) -> bool
[src]
Returns whether self
and other
are equal in color.
pub fn is_aligned(self, a: Square, b: Square) -> bool
[src]
Returns whether self
is aligned with two other squares along a file,
rank, or diagonal.
Examples
Square A3 lies on the same diagonal as C5 and F8:
assert!(Square::A3.is_aligned(Square::C5, Square::F8));
pub fn is_between(self, a: Square, b: Square) -> bool
[src]
Returns whether self
is between two other squares along a file, rank,
or diagonal.
Examples
Square D4 lies between B2 and G7 along a diagonal:
assert!(Square::D4.is_between(Square::B2, Square::G7));
pub fn distance(self, other: Square) -> usize
[src]
Calculates the Chebyshev distance between self
and other
.
The result is the number of steps required to move a king from one square to the other.
Examples
It takes a king two moves to travel the same distance as a knight:
for s1 in Square::ALL { for s2 in s1.knight_attacks() { assert_eq!(s1.distance(s2), 2); } }
pub fn man_distance(self, other: Square) -> usize
[src]
Calculates the Manhattan distance between self
and other
.
The result is the distance when strictly taking a horizontal/vertical path from one square to the other.
Examples
The knight's path always traverses three squares:
for s1 in Square::ALL { for s2 in s1.knight_attacks() { assert_eq!(s1.man_distance(s2), 3); } }
pub fn center_distance(self) -> usize
[src]
Calculates the Chebyshev distance between self
and the center
of the board.
Examples
It takes a king three moves to travel to the center of the board from any edge:
let edges = File::A | File::H | Rank::One | Rank::Eight; for sq in edges { assert_eq!(sq.center_distance(), 3); }
pub fn center_man_distance(self) -> usize
[src]
Calculates the Manhattan distance between self
and the center
of the board.
pub fn tri_index(self, other: Square) -> usize
[src]
Returns the triangular index for self
and other
.
This allows indexing into tables of size 2080, which is slightly greater than 2048 (64 × 64 ÷ 2).
Tradeoffs
While this allows for using 50.78% as much memory as a table of size 4096 (64 × 64), computing the index takes a considerable amount of time compared to indexing into a 64 × 64 table.
Safety
The result index has been thoroughly tested to always return a value
less than 2080. Because of this, it is safe to call get_unchecked
on
arrays/slices of that size or greater.
pub fn tri<T>(self, other: Square, table: &[T; 2080]) -> &T
[src]
Returns a shared reference to an element from the table via triangular index.
pub fn tri_mut<T>(self, other: Square, table: &mut [T; 2080]) -> &mut T
[src]
Returns a mutable reference to an element from the table via triangular index.
pub fn map_str<T, F: FnOnce(&mut str) -> T>(self, f: F) -> T
[src]
Returns the result of applying a function to a mutable string
representation of self
.
This is a much preferred way of getting the string representation of
a square, especially in when using #![no_std]
. The alternative would
be to use to_string
or format!
, which perform a heap allocation
whereas this uses a stack-allocated string.
Examples
The string's lifetime is for the duration of the closure's execution:
Square::A5.map_str(|s| assert_eq!(s, "A5"));
ⓘImportant traits for Bitboardpub fn pawn_attacks(self, color: Color) -> Bitboard
[src]
Returns the pawn attacks for self
and color
.
ⓘImportant traits for Bitboardpub fn knight_attacks(self) -> Bitboard
[src]
Returns the knight attacks for self
.
ⓘImportant traits for Bitboardpub fn rook_attacks(self, occupied: Bitboard) -> Bitboard
[src]
Returns the rook attacks for self
and occupied
.
Whether or not occupied
contains self
does not matter.
Examples
Basic usage:
let start = Square::A1; let occ = Square::A3 | Square::C1; let exp = Square::A2 | Square::B1 | occ; assert_eq!(start.rook_attacks(occ), exp);
ⓘImportant traits for Bitboardpub fn bishop_attacks(self, occupied: Bitboard) -> Bitboard
[src]
Returns the bishop attacks for self
and occupied
.
Whether or not occupied
contains self
does not matter.
Examples
Basic usage:
let start = Square::A1; let occ = Square::C3; let exp = Square::B2 | occ; assert_eq!(start.bishop_attacks(occ.into()), exp);
ⓘImportant traits for Bitboardpub fn king_attacks(self) -> Bitboard
[src]
Returns the king attacks for self
.
ⓘImportant traits for Bitboardpub fn queen_attacks(self, occupied: Bitboard) -> Bitboard
[src]
Returns the queen attacks for self
and occupied
.
This works the same as combining the results of rook_attacks
and
bishop_attacks
.
Trait Implementations
impl<T: Into<Bitboard>> BitOr<T> for Square
[src]
type Output = Bitboard
The resulting type after applying the |
operator.
ⓘImportant traits for Bitboardfn bitor(self, other: T) -> Bitboard
[src]
Performs the |
operation.
impl<T: Into<Bitboard>> BitAnd<T> for Square
[src]
type Output = Bitboard
The resulting type after applying the &
operator.
ⓘImportant traits for Bitboardfn bitand(self, other: T) -> Bitboard
[src]
Performs the &
operation.
impl<T: Into<Bitboard>> BitXor<T> for Square
[src]
type Output = Bitboard
The resulting type after applying the ^
operator.
ⓘImportant traits for Bitboardfn bitxor(self, other: T) -> Bitboard
[src]
Performs the ^
operation.
impl From<Square> for Bitboard
[src]
impl Index<Square> for PieceMap
[src]
type Output = Piece
The returned type after indexing.
fn index(&self, sq: Square) -> &Piece
[src]
Performs the indexing (container[index]
) operation.
impl IndexMut<Square> for PieceMap
[src]
fn index_mut(&mut self, sq: Square) -> &mut Piece
[src]
Performs the mutable indexing (container[index]
) operation.
impl<'a> Contained<&'a PieceMap> for Square
[src]
fn contained_in(self, map: &PieceMap) -> bool
[src]
Returns whether self
is contained in other
.
impl Swap for Square
[src]
impl<T> Extract<[T; 64]> for Square
[src]
type Output = T
The output type.
fn extract<'a>(self, buf: &'a [T; 64]) -> &'a T
[src]
Extracts a reference to the value for self
within buf
.
fn extract_mut<'a>(self, buf: &'a mut [T; 64]) -> &'a mut T
[src]
Extracts a mutable reference to the value for self
within buf
.
impl Copy for Square
[src]
impl Clone for Square
[src]
fn clone(&self) -> Square
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Hash for Square
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialEq for Square
[src]
fn eq(&self, __arg_0: &Square) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Eq for Square
[src]
impl PartialOrd for Square
[src]
fn partial_cmp(&self, __arg_0: &Square) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for Square
[src]
fn cmp(&self, __arg_0: &Square) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl FromUnchecked<u8> for Square
[src]
unsafe fn from_unchecked(inner: u8) -> Self
[src]
Performs the unchecked conversion.
impl From<u8> for Square
[src]
impl FromUnchecked<u16> for Square
[src]
unsafe fn from_unchecked(inner: u16) -> Self
[src]
Performs the unchecked conversion.
impl From<u16> for Square
[src]
impl FromUnchecked<u32> for Square
[src]
unsafe fn from_unchecked(inner: u32) -> Self
[src]
Performs the unchecked conversion.
impl From<u32> for Square
[src]
impl FromUnchecked<u64> for Square
[src]
unsafe fn from_unchecked(inner: u64) -> Self
[src]
Performs the unchecked conversion.
impl From<u64> for Square
[src]
impl FromUnchecked<usize> for Square
[src]
unsafe fn from_unchecked(inner: usize) -> Self
[src]
Performs the unchecked conversion.
impl From<usize> for Square
[src]
impl Debug for Square
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Display for Square
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl From<(File, Rank)> for Square
[src]
impl FromStr for Square
[src]
type Err = FromStrError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Square, FromStrError>
[src]
Parses a string s
to return a value of this type. Read more