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

Methods

impl Square
[src]

[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);

[src]

Returns the File for self.

[src]

Returns the Rank for self.

[src]

Reverses the file of self.

Examples

assert_eq!(Square::B2.rev_file(), Square::G2);

[src]

Reverses the rank of self.

Examples

assert_eq!(Square::B2.rev_rank(), Square::B7);

[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);

[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);

[src]

Returns whether self and other are equal in color.

[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));

[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));

[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);
    }
}

[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);
    }
}

[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);
}

[src]

Calculates the Manhattan distance between self and the center of the board.

[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.

[src]

Returns a shared reference to an element from the table via triangular index.

[src]

Returns a mutable reference to an element from the table via triangular index.

[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 Bitboard
[src]

Returns the pawn attacks for self and color.

Important traits for Bitboard
[src]

Returns the knight attacks for self.

Important traits for 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 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 Bitboard
[src]

Returns the king attacks for self.

Important traits for 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]

The resulting type after applying the | operator.

Important traits for Bitboard
[src]

Performs the | operation.

impl<T: Into<Bitboard>> BitAnd<T> for Square
[src]

The resulting type after applying the & operator.

Important traits for Bitboard
[src]

Performs the & operation.

impl<T: Into<Bitboard>> BitXor<T> for Square
[src]

The resulting type after applying the ^ operator.

Important traits for Bitboard
[src]

Performs the ^ operation.

impl From<Square> for Bitboard
[src]

[src]

Performs the conversion.

impl Index<Square> for PieceMap
[src]

The returned type after indexing.

[src]

Performs the indexing (container[index]) operation.

impl IndexMut<Square> for PieceMap
[src]

[src]

Performs the mutable indexing (container[index]) operation.

impl<'a> Contained<&'a PieceMap> for Square
[src]

[src]

Returns whether self is contained in other.

impl Swap for Square
[src]

[src]

Swaps the values at i and j in map.

impl<T> Extract<[T; 64]> for Square
[src]

The output type.

[src]

Extracts a reference to the value for self within buf.

[src]

Extracts a mutable reference to the value for self within buf.

impl Copy for Square
[src]

impl Clone for Square
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Hash for Square
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl PartialEq for Square
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl Eq for Square
[src]

impl PartialOrd for Square
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

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]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl FromUnchecked<u8> for Square
[src]

[src]

Performs the unchecked conversion.

impl From<u8> for Square
[src]

[src]

Performs the conversion.

impl FromUnchecked<u16> for Square
[src]

[src]

Performs the unchecked conversion.

impl From<u16> for Square
[src]

[src]

Performs the conversion.

impl FromUnchecked<u32> for Square
[src]

[src]

Performs the unchecked conversion.

impl From<u32> for Square
[src]

[src]

Performs the conversion.

impl FromUnchecked<u64> for Square
[src]

[src]

Performs the unchecked conversion.

impl From<u64> for Square
[src]

[src]

Performs the conversion.

impl FromUnchecked<usize> for Square
[src]

[src]

Performs the unchecked conversion.

impl From<usize> for Square
[src]

[src]

Performs the conversion.

impl Debug for Square
[src]

[src]

Formats the value using the given formatter. Read more

impl Display for Square
[src]

[src]

Formats the value using the given formatter. Read more

impl From<(File, Rank)> for Square
[src]

[src]

Performs the conversion.

impl FromStr for Square
[src]

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more

Auto Trait Implementations

impl Send for Square

impl Sync for Square