[−][src]Struct chess::Square
Represent a square on the chess board
Methods
impl Square
[src]
pub unsafe fn new(sq: u8) -> Square
[src]
Create a new square, given an index. Note: It is invalid, but allowed, to pass in a number >= 64. Doing so will crash stuff.
use chess::{Square, Rank, File, EMPTY}; assert_eq!(unsafe { Square::new(0) }, Square::default()); let bad_sq = unsafe { Square::new(64) }; // Iterate over all possible squares and ensure that *none* of them are equal to `bad_sq`. for sq in !EMPTY { assert_ne!(bad_sq, sq); }
pub fn make_square(rank: Rank, file: File) -> Square
[src]
Make a square given a rank and a file
use chess::{Square, Rank, File, BitBoard}; // Make the A1 square let sq = Square::make_square(Rank::First, File::A); // Convert it to a bitboard let bb = BitBoard::from_square(sq); // loop over all squares in the bitboard (should be only one), and ensure that the square // is what we created for x in bb { assert_eq!(sq, x); }
pub fn get_rank(&self) -> Rank
[src]
Return the rank given this square.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Seventh, File::D); assert_eq!(sq.get_rank(), Rank::Seventh);
pub fn get_file(&self) -> File
[src]
Return the file given this square.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Seventh, File::D); assert_eq!(sq.get_file(), File::D);
pub fn up(&self) -> Option<Square>
[src]
If there is a square above me, return that. Otherwise, None.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Seventh, File::D); assert_eq!(sq.up().expect("Valid Square"), Square::make_square(Rank::Eighth, File::D)); assert_eq!(sq.up().expect("Valid Square").up(), None);
pub fn down(&self) -> Option<Square>
[src]
If there is a square below me, return that. Otherwise, None.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Second, File::D); assert_eq!(sq.down().expect("Valid Square"), Square::make_square(Rank::First, File::D)); assert_eq!(sq.down().expect("Valid Square").down(), None);
pub fn left(&self) -> Option<Square>
[src]
If there is a square to the left of me, return that. Otherwise, None.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Seventh, File::B); assert_eq!(sq.left().expect("Valid Square"), Square::make_square(Rank::Seventh, File::A)); assert_eq!(sq.left().expect("Valid Square").left(), None);
pub fn right(&self) -> Option<Square>
[src]
If there is a square to the right of me, return that. Otherwise, None.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Seventh, File::G); assert_eq!(sq.right().expect("Valid Square"), Square::make_square(Rank::Seventh, File::H)); assert_eq!(sq.right().expect("Valid Square").right(), None);
pub fn forward(&self, color: Color) -> Option<Square>
[src]
If there is a square "forward", given my Color
, go in that direction. Otherwise, None.
use chess::{Square, Rank, File, Color}; let mut sq = Square::make_square(Rank::Seventh, File::D); assert_eq!(sq.forward(Color::White).expect("Valid Square"), Square::make_square(Rank::Eighth, File::D)); assert_eq!(sq.forward(Color::White).expect("Valid Square").forward(Color::White), None); sq = Square::make_square(Rank::Second, File::D); assert_eq!(sq.forward(Color::Black).expect("Valid Square"), Square::make_square(Rank::First, File::D)); assert_eq!(sq.forward(Color::Black).expect("Valid Square").forward(Color::Black), None);
pub fn backward(&self, color: Color) -> Option<Square>
[src]
If there is a square "backward" given my Color
, go in that direction. Otherwise, None.
use chess::{Square, Rank, File, Color}; let mut sq = Square::make_square(Rank::Seventh, File::D); assert_eq!(sq.backward(Color::Black).expect("Valid Square"), Square::make_square(Rank::Eighth, File::D)); assert_eq!(sq.backward(Color::Black).expect("Valid Square").backward(Color::Black), None); sq = Square::make_square(Rank::Second, File::D); assert_eq!(sq.backward(Color::White).expect("Valid Square"), Square::make_square(Rank::First, File::D)); assert_eq!(sq.backward(Color::White).expect("Valid Square").backward(Color::White), None);
pub fn uup(&self) -> Square
[src]
If there is a square above me, return that. If not, wrap around to the other side.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Seventh, File::D); assert_eq!(sq.uup(), Square::make_square(Rank::Eighth, File::D)); assert_eq!(sq.uup().uup(), Square::make_square(Rank::First, File::D));
pub fn udown(&self) -> Square
[src]
If there is a square below me, return that. If not, wrap around to the other side.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Second, File::D); assert_eq!(sq.udown(), Square::make_square(Rank::First, File::D)); assert_eq!(sq.udown().udown(), Square::make_square(Rank::Eighth, File::D));
pub fn uleft(&self) -> Square
[src]
If there is a square to the left of me, return that. If not, wrap around to the other side.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Seventh, File::B); assert_eq!(sq.uleft(), Square::make_square(Rank::Seventh, File::A)); assert_eq!(sq.uleft().uleft(), Square::make_square(Rank::Seventh, File::H));
pub fn uright(&self) -> Square
[src]
If there is a square to the right of me, return that. If not, wrap around to the other side.
use chess::{Square, Rank, File}; let sq = Square::make_square(Rank::Seventh, File::G); assert_eq!(sq.uright(), Square::make_square(Rank::Seventh, File::H)); assert_eq!(sq.uright().uright(), Square::make_square(Rank::Seventh, File::A));
pub fn uforward(&self, color: Color) -> Square
[src]
If there is a square "forward", given my color, return that. If not, wrap around to the other side.
use chess::{Square, Rank, File, Color}; let mut sq = Square::make_square(Rank::Seventh, File::D); assert_eq!(sq.uforward(Color::White), Square::make_square(Rank::Eighth, File::D)); assert_eq!(sq.uforward(Color::White).uforward(Color::White), Square::make_square(Rank::First, File::D)); sq = Square::make_square(Rank::Second, File::D); assert_eq!(sq.uforward(Color::Black), Square::make_square(Rank::First, File::D)); assert_eq!(sq.uforward(Color::Black).uforward(Color::Black), Square::make_square(Rank::Eighth, File::D));
pub fn ubackward(&self, color: Color) -> Square
[src]
If there is a square "backward", given my color, return that. If not, wrap around to the other side.
use chess::{Square, Rank, File, Color}; let mut sq = Square::make_square(Rank::Seventh, File::D); assert_eq!(sq.ubackward(Color::Black), Square::make_square(Rank::Eighth, File::D)); assert_eq!(sq.ubackward(Color::Black).ubackward(Color::Black), Square::make_square(Rank::First, File::D)); sq = Square::make_square(Rank::Second, File::D); assert_eq!(sq.ubackward(Color::White), Square::make_square(Rank::First, File::D)); assert_eq!(sq.ubackward(Color::White).ubackward(Color::White), Square::make_square(Rank::Eighth, File::D));
pub fn to_int(&self) -> u8
[src]
Convert this square to an integer.
use chess::{Square, Rank, File}; assert_eq!(Square::make_square(Rank::First, File::A).to_int(), 0); assert_eq!(Square::make_square(Rank::Second, File::A).to_int(), 8); assert_eq!(Square::make_square(Rank::First, File::B).to_int(), 1); assert_eq!(Square::make_square(Rank::Eighth, File::H).to_int(), 63);
pub fn to_index(&self) -> usize
[src]
Convert this Square
to a usize
for table lookup purposes
use chess::{Square, Rank, File}; assert_eq!(Square::make_square(Rank::First, File::A).to_index(), 0); assert_eq!(Square::make_square(Rank::Second, File::A).to_index(), 8); assert_eq!(Square::make_square(Rank::First, File::B).to_index(), 1); assert_eq!(Square::make_square(Rank::Eighth, File::H).to_index(), 63);
pub fn from_string(s: String) -> Option<Square>
[src]
Convert a UCI String
to a square. If invalid, return None
use chess::Square; let sq = Square::default(); assert_eq!(Square::from_string("a1".to_owned()).expect("Valid Square"), sq);
Trait Implementations
impl Default for Square
[src]
fn default() -> Square
[src]
Create a square on A1.
use chess::{Square, Rank, File}; let explicit_sq = Square::make_square(Rank::First, File::A); let implicit_sq = Square::default(); assert_eq!(explicit_sq, implicit_sq);
impl Clone for Square
[src]
fn clone(&self) -> Square
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Ord for Square
[src]
fn cmp(&self, other: &Square) -> Ordering
[src]
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
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl Eq for Square
[src]
impl Copy for Square
[src]
impl PartialOrd<Square> for Square
[src]
fn partial_cmp(&self, other: &Square) -> Option<Ordering>
[src]
fn lt(&self, other: &Square) -> bool
[src]
fn le(&self, other: &Square) -> bool
[src]
fn gt(&self, other: &Square) -> bool
[src]
fn ge(&self, other: &Square) -> bool
[src]
impl PartialEq<Square> for Square
[src]
impl Debug for Square
[src]
impl Display for Square
[src]
impl Hash for Square
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,