Struct shogi::Square
[−]
[src]
pub struct Square { /* fields omitted */ }Represents a position of each cell in the game board.
Examples
use shogi::Square; // (4, 4) represents 5e. let sq = Square::new(4, 4); 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]
fn new(file: u8, rank: u8) -> Square
Creates a new instance of Square.
file and rank need to be lower than 9 the returned instance to be valid value.
fn from_sfen(s: &str) -> Option<Square>
Creates a new instance of Square from SFEN formatted string.
fn file(&self) -> u8
Returns a file of the square.
fn rank(&self) -> u8
Returns a rank of the square.
fn is_valid(&self) -> bool
Tests if both the file and the rank are valid values.
Examples
use shogi::Square; assert!(Square::new(0, 0).is_valid()); assert!(!Square::new(9, 9).is_valid());
fn shift(&self, df: i8, dr: i8) -> Square
Returns a new Square instance by moving the file and the rank values.
Examples
use shogi::Square; let sq = Square::new(1, 1); let shifted = sq.shift(2, 3); assert_eq!(3, shifted.file()); assert_eq!(4, shifted.rank());
fn relative_rank(&self, c: Color) -> u8
Returns a relative rank as if the specified color is black.
Examples
use shogi::{Color, Square}; let sq = Square::new(0, 6); assert_eq!(6, sq.relative_rank(Color::Black)); assert_eq!(2, sq.relative_rank(Color::White));
fn in_promotion_zone(&self, c: Color) -> bool
Tests if the square is in a promotion zone.
Trait Implementations
impl Debug for Square[src]
impl PartialEq for Square[src]
fn eq(&self, __arg_0: &Square) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &Square) -> bool
This method tests for !=.
impl Eq for Square[src]
impl Clone for Square[src]
fn clone(&self) -> Square
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0
Performs copy-assignment from source. Read more
impl Copy for Square[src]
impl Hash for Square[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher1.3.0
Feeds a slice of this type into the state provided.