Struct shogi::Position
[−]
[src]
pub struct Position { /* fields omitted */ }Represents a state of the game.
Examples
use shogi::{Move, Position, Square}; let mut pos = Position::new(); pos.set_sfen("lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1").unwrap(); let m = Move::Normal{from: Square::new(2, 6), to: Square::new(2, 5), promote: false}; pos.make_move(&m).unwrap(); assert_eq!("lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves 7g7f", pos.to_sfen());
Methods
impl Position[src]
fn new() -> Position
Creates a new instance of Position with an empty board.
fn piece_at(&self, sq: Square) -> &Option<Piece>
Returns a piece at the given square.
fn set_piece(&mut self, sq: Square, p: Option<Piece>)
Sets a piece at the given square.
fn hand(&self, p: &Piece) -> u8
Returns the number of the given piece in hand.
fn side_to_move(&self) -> Color
Returns the side to make a move next.
fn ply(&self) -> u16
Returns the number of plies already completed by the current state.
fn move_history(&self) -> &[MoveRecord]
Returns a history of all moves made since the beginning of the game.
fn in_check(&self, c: Color) -> bool
Checks if the king with the given color is in check.
fn make_move(&mut self, m: &Move) -> Result<(), MoveError>
Makes the given move. Returns Err if the move is invalid or any special condition is met.
fn unmake_move(&mut self) -> Result<(), MoveError>
Undoes the last move.
fn move_candidates(&self, sq: Square, p: &Piece) -> Vec<Square>
Returns a list of squares to where the given pieve at the given square can move.
fn set_sfen(&mut self, sfen_str: &str) -> Result<(), SfenError>
Parses the given SFEN string and updates the game state.
fn to_sfen(&self) -> String
Converts the current state into SFEN formatted string.