pub struct Square { /* private fields */ }
Expand description
Represents a position of each cell in the game board.
Examples
use shuuro::Square;
let sq = Square::new(4, 4).unwrap();
assert_eq!("e5", sq.to_string());
Square
can be created by parsing a SFEN formatted string as well.
use shuuro::Square;
let sq = Square::from_sfen("e5").unwrap();
assert_eq!(4, sq.file());
assert_eq!(4, sq.rank());
Implementations
sourceimpl Square
impl Square
sourcepub fn new(file: u8, rank: u8) -> Option<Square>
pub fn new(file: u8, rank: u8) -> Option<Square>
Creates a new instance of Square
.
file
can take a value from 0(‘1’) to 11(‘12’), while rank
is from 0(‘a’) to 12(‘l’).
sourcepub fn from_sfen(s: &str) -> Option<Square>
pub fn from_sfen(s: &str) -> Option<Square>
Creates a new instance of Square
from SFEN formatted string.
sourcepub fn from_index(index: u8) -> Option<Square>
pub fn from_index(index: u8) -> Option<Square>
Creates a new instance of Square
with the given index value.
sourcepub fn iter() -> SquareIterⓘNotable traits for SquareIterimpl Iterator for SquareIter type Item = Square;
pub fn iter() -> SquareIterⓘNotable traits for SquareIterimpl Iterator for SquareIter type Item = Square;
Returns an iterator of all variants.
sourcepub fn shift(self, df: i16, dr: i16) -> Option<Square>
pub fn shift(self, df: i16, dr: i16) -> Option<Square>
Returns a new Square
instance by moving the file and the rank values.
Examples
use shuuro::square::consts::*;
let sq = B2;
let shifted = sq.shift(2, 3).unwrap();
assert_eq!(3, shifted.file());
assert_eq!(4, shifted.rank());
sourcepub fn relative_file(self, c: Color) -> u8
pub fn relative_file(self, c: Color) -> u8
Returns a relative rank as if the specified color is Black.
sourcepub fn in_promotion_zone(self, c: Color) -> bool
pub fn in_promotion_zone(self, c: Color) -> bool
Tests if the square is in a promotion zone.
Trait Implementations
sourceimpl<'a> BitAndAssign<Square> for BitBoard
impl<'a> BitAndAssign<Square> for BitBoard
sourcefn bitand_assign(&mut self, rhs: Square)
fn bitand_assign(&mut self, rhs: Square)
Performs the &=
operation. Read more
sourceimpl<'a> BitOrAssign<Square> for BitBoard
impl<'a> BitOrAssign<Square> for BitBoard
sourcefn bitor_assign(&mut self, rhs: Square)
fn bitor_assign(&mut self, rhs: Square)
Performs the |=
operation. Read more
sourceimpl<'a> BitXorAssign<Square> for BitBoard
impl<'a> BitXorAssign<Square> for BitBoard
sourcefn bitxor_assign(&mut self, rhs: Square)
fn bitxor_assign(&mut self, rhs: Square)
Performs the ^=
operation. Read more
impl Copy for Square
impl Eq for Square
impl StructuralEq for Square
Auto Trait Implementations
impl RefUnwindSafe for Square
impl Send for Square
impl Sync for Square
impl Unpin for Square
impl UnwindSafe for Square
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more