[][src]Struct shogi::square::Square

pub struct Square { /* fields omitted */ }

Represents a position of each cell in the game board.

Examples

use shogi::Square;

let sq = Square::new(4, 4).unwrap();
assert_eq!("5e", sq.to_string());

Square can be created by parsing a SFEN formatted string as well.

use shogi::Square;

let sq = Square::from_sfen("5e").unwrap();
assert_eq!(4, sq.file());
assert_eq!(4, sq.rank());

Methods

impl Square
[src]

pub fn new(file: u8, rank: u8) -> Option<Square>
[src]

Creates a new instance of Square.

file can take a value from 0('1') to 8('9'), while rank is from 0('a') to 9('i').

pub fn from_sfen(s: &str) -> Option<Square>
[src]

Creates a new instance of Square from SFEN formatted string.

pub fn from_index(index: u8) -> Option<Square>
[src]

Creates a new instance of Square with the given index value.

Important traits for SquareIter
pub fn iter() -> SquareIter
[src]

Returns an iterator of all variants.

pub fn file(&self) -> u8
[src]

Returns a file of the square.

pub fn rank(&self) -> u8
[src]

Returns a rank of the square.

pub fn shift(&self, df: i8, dr: i8) -> Option<Square>
[src]

Returns a new Square instance by moving the file and the rank values.

Examples

use shogi::square::consts::*;

let sq = SQ_2B;
let shifted = sq.shift(2, 3).unwrap();

assert_eq!(3, shifted.file());
assert_eq!(4, shifted.rank());

pub fn relative_rank(&self, c: Color) -> u8
[src]

Returns a relative rank as if the specified color is black.

Examples

use shogi::Color;
use shogi::square::consts::*;

let sq = SQ_1G;

assert_eq!(6, sq.relative_rank(Color::Black));
assert_eq!(2, sq.relative_rank(Color::White));

pub fn in_promotion_zone(&self, c: Color) -> bool
[src]

Tests if the square is in a promotion zone.

pub fn index(&self) -> usize
[src]

Converts the instance into the unique number for array indexing purpose.

Trait Implementations

impl PartialEq<Square> for Square
[src]

impl Eq for Square
[src]

impl Clone for Square
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Copy for Square
[src]

impl Display for Square
[src]

impl Debug for Square
[src]

impl Hash for Square
[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

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

impl<'a> BitAnd<Square> for &'a Bitboard
[src]

type Output = Bitboard

The resulting type after applying the & operator.

impl<'a> BitOr<Square> for &'a Bitboard
[src]

type Output = Bitboard

The resulting type after applying the | operator.

impl<'a> BitXor<Square> for &'a Bitboard
[src]

type Output = Bitboard

The resulting type after applying the ^ operator.

impl<'a> BitAndAssign<Square> for Bitboard
[src]

impl<'a> BitOrAssign<Square> for Bitboard
[src]

impl<'a> BitXorAssign<Square> for Bitboard
[src]

Auto Trait Implementations

impl Send for Square

impl Sync for Square

Blanket Implementations

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

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

type Owned = T

impl<T> From for T
[src]

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

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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