[][src]Struct shogi::position::Position

pub struct Position { /* fields omitted */ }

Represents a state of the game.

Examples

use shogi::{Move, Position};
use shogi::bitboard::Factory as BBFactory;
use shogi::square::consts::*;

BBFactory::init();
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: SQ_7G, to: SQ_7F, 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]

pub fn new() -> Position
[src]

Creates a new instance of Position with an empty board.

pub fn piece_at(&self, sq: Square) -> &Option<Piece>
[src]

Returns a piece at the given square.

Important traits for Bitboard
pub fn player_bb(&self, c: Color) -> &Bitboard
[src]

Returns a bitboard containing pieces of the given player.

pub fn hand(&self, p: &Piece) -> u8
[src]

Returns the number of the given piece in hand.

pub fn side_to_move(&self) -> Color
[src]

Returns the side to make a move next.

pub fn ply(&self) -> u16
[src]

Returns the number of plies already completed by the current state.

pub fn move_history(&self) -> &[MoveRecord]
[src]

Returns a history of all moves made since the beginning of the game.

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

Checks if a player with the given color can declare winning.

See the section 25 in http://www.computer-shogi.org/wcsc26/rule.pdf for more detail.

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

Checks if the king with the given color is in check.

pub fn make_move(&mut self, m: &Move) -> Result<(), MoveError>
[src]

Makes the given move. Returns Err if the move is invalid or any special condition is met.

pub fn unmake_move(&mut self) -> Result<(), MoveError>
[src]

Undoes the last move.

Important traits for Bitboard
pub fn move_candidates(&self, sq: Square, p: &Piece) -> Bitboard
[src]

Returns a list of squares to where the given pieve at the given square can move.

pub fn set_sfen(&mut self, sfen_str: &str) -> Result<(), SfenError>
[src]

Parses the given SFEN string and updates the game state.

pub fn to_sfen(&self) -> String
[src]

Converts the current state into SFEN formatted string.

Trait Implementations

impl Default for Position
[src]

impl Display for Position
[src]

impl Debug for Position
[src]

Auto Trait Implementations

impl Send for Position

impl Sync for Position

Blanket Implementations

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

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]