[][src]Enum shakmaty::Square

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

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

Implementations

impl Square[src]

pub fn new(index: u32) -> Square[src]

Gets a Square from an integer index.

Panics

Panics if the index is not in the range 0..=63.

Examples

use shakmaty::Square;

assert_eq!(Square::new(0), Square::A1);
assert_eq!(Square::new(63), Square::H8);

pub unsafe fn new_unchecked(index: u32) -> Square[src]

Gets a Square from an integer index.

Safety

It is the callers responsibility to ensure it is in the range 0..=63.

pub fn from_coords(file: File, rank: Rank) -> Square[src]

Tries to get a square from file and rank.

Examples

use shakmaty::{Square, File, Rank};

assert_eq!(Square::from_coords(File::A, Rank::First), Square::A1);

pub fn from_ascii(s: &[u8]) -> Result<Square, ParseSquareError>[src]

Parses a square name.

Errors

Returns ParseSquareError if the input is not a valid square name in lowercase ASCII characters.

Example

use shakmaty::Square;

let sq = Square::from_ascii(b"a5")?;
assert_eq!(sq, Square::A5);

pub fn file(self) -> File[src]

Gets the file.

Examples

use shakmaty::{Square, File};

assert_eq!(Square::A1.file(), File::A);
assert_eq!(Square::B2.file(), File::B);

pub fn rank(self) -> Rank[src]

Gets the rank.

Examples

use shakmaty::{Square, Rank};

assert_eq!(Square::A1.rank(), Rank::First);
assert_eq!(Square::B2.rank(), Rank::Second);

pub fn coords(self) -> (File, Rank)[src]

Gets file and rank.

Examples

use shakmaty::{Square, File, Rank};

assert_eq!(Square::A1.coords(), (File::A, Rank::First));
assert_eq!(Square::H8.coords(), (File::H, Rank::Eighth));

#[must_use]pub fn offset(self, delta: i32) -> Option<Square>[src]

Calculates the offset from a square index.

Examples

use shakmaty::Square;

assert_eq!(Square::F3.offset(8), Some(Square::F4));
assert_eq!(Square::F3.offset(-1), Some(Square::E3));

assert_eq!(Square::F3.offset(48), None);

#[must_use]pub fn flip_horizontal(self) -> Square[src]

Flip the square horizontally.

use shakmaty::Square;

assert_eq!(Square::H1.flip_horizontal(), Square::A1);
assert_eq!(Square::D3.flip_horizontal(), Square::E3);

#[must_use]pub fn flip_vertical(self) -> Square[src]

Flip the square vertically.

use shakmaty::Square;

assert_eq!(Square::A8.flip_vertical(), Square::A1);
assert_eq!(Square::D3.flip_vertical(), Square::D6);

#[must_use]pub fn flip_diagonal(self) -> Square[src]

Flip at the a1-h8 diagonal by swapping file and rank.

use shakmaty::Square;

assert_eq!(Square::A1.flip_diagonal(), Square::A1);
assert_eq!(Square::A3.flip_diagonal(), Square::C1);

#[must_use]pub fn flip_anti_diagonal(self) -> Square[src]

Flip at the h1-a8 diagonal.

use shakmaty::Square;

assert_eq!(Square::A1.flip_anti_diagonal(), Square::H8);
assert_eq!(Square::A3.flip_anti_diagonal(), Square::F8);

#[must_use]pub fn rotate_90(self) -> Square[src]

Rotate 90 degrees clockwise.

use shakmaty::Square;

assert_eq!(Square::A1.rotate_90(), Square::A8);
assert_eq!(Square::A3.rotate_90(), Square::C8);

#[must_use]pub fn rotate_180(self) -> Square[src]

Rotate 180 degrees clockwise.

use shakmaty::Square;

assert_eq!(Square::A1.rotate_180(), Square::H8);
assert_eq!(Square::A3.rotate_180(), Square::H6);

#[must_use]pub fn rotate_270(self) -> Square[src]

Rotate 270 degrees clockwise.

use shakmaty::Square;

assert_eq!(Square::A1.rotate_270(), Square::H1);
assert_eq!(Square::A3.rotate_270(), Square::F1);

pub fn is_light(self) -> bool[src]

Tests is the square is a light square.

use shakmaty::Square;

assert!(Square::D1.is_light());
assert!(!Square::D8.is_light());

pub fn is_dark(self) -> bool[src]

Tests is the square is a dark square.

use shakmaty::Square;

assert!(Square::E1.is_dark());
assert!(!Square::E8.is_dark());

pub fn distance(self, other: Square) -> u32[src]

The distance between the two squares, i.e. the number of king steps to get from one square to the other.

use shakmaty::Square;

assert_eq!(Square::A2.distance(Square::B5), 3);

Trait Implementations

impl Clone for Square[src]

impl Copy for Square[src]

impl Debug for Square[src]

impl Display for Square[src]

impl Eq for Square[src]

impl Extend<Square> for Bitboard[src]

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

impl From<Square> for Bitboard[src]

impl FromIterator<Square> for Bitboard[src]

impl FromStr for Square[src]

type Err = ParseSquareError

The associated error which can be returned from parsing.

impl Hash for Square[src]

impl Ord for Square[src]

impl PartialEq<Square> for Square[src]

impl PartialOrd<Square> for Square[src]

impl StructuralEq for Square[src]

impl StructuralPartialEq for Square[src]

impl Sub<Square> for Square[src]

type Output = i32

The resulting type after applying the - operator.

impl TryFrom<i128> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i16> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i32> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i64> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<i8> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<isize> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<u128> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<u16> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<u32> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<u64> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<u8> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

impl TryFrom<usize> for Square[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.