Chess

Struct Chess 

Source
pub struct Chess {
    pub board: Board,
    pub turn: Color,
    pub kings: Kings,
    pub castling_rights: CastlingRights,
    pub history: MoveHistory,
    pub white_captures: Vec<Piece>,
    pub black_captures: Vec<Piece>,
    pub half_moves: u8,
    pub full_moves: u8,
    pub en_passant_sq: Option<SquareCoordinate>,
    /* private fields */
}

Fields§

§board: Board§turn: Color§kings: Kings

the kings’ positions on the board

§castling_rights: CastlingRights§history: MoveHistory§white_captures: Vec<Piece>§black_captures: Vec<Piece>§half_moves: u8§full_moves: u8§en_passant_sq: Option<SquareCoordinate>

Implementations§

Source§

impl Chess

Source

pub fn new() -> Self

Source

pub fn play_move(&mut self, m: Move) -> Result<(), ChessError>

Make a move on the board

Source

pub fn make_move(&mut self, m: Move) -> Result<(), ChessError>

Source

pub fn undo_move(&mut self) -> Result<(), ChessError>

Source

pub fn moves_for_piece_type()

Get all legal moves for a specific piece type

Source

pub fn moves_for_square( &mut self, sq: SquareCoordinate, ) -> Result<Vec<Move>, ChessError>

Get all legal moves for the piece on the specified square

Source

pub fn moves(&mut self) -> Result<Vec<Move>, ChessError>

Get all legal moves for the player to move

Source

pub fn in_check(&self) -> Result<bool, ChessError>

Return true if the current player to move is in check

Source

pub fn is_checkmate(&mut self) -> Result<bool, ChessError>

Source

pub fn is_draw(&mut self) -> Result<bool, ChessError>

Source

pub fn is_stalemate(&mut self) -> Result<bool, ChessError>

Source

pub fn is_insufficient_material(&self) -> Result<bool, ChessError>

Source

pub fn is_50_moves(&self) -> Result<bool, ChessError>

Source

pub fn is_threefold_repetition(&self) -> Result<bool, ChessError>

Source

pub fn is_attacked(&self, from: SquareCoordinate) -> Result<bool, ChessError>

Check if a square is attacked by opponent pieces

Source

pub fn change_turn(&mut self)

Source

pub fn get(&self, sq: SquareCoordinate) -> Result<Option<Piece>, ChessError>

Return the PieceType and its associated value on a square. Return an ChessError if the index is out of range.

Some(t) means an occupied square, None means the square is empty.

Source

pub fn set( &mut self, sq: SquareCoordinate, piece: PieceType, color: Color, ) -> Result<(Piece, usize), ChessError>

Put a piece at specific index on the board. Return the piece and index if succeed, or an ChessError if not.

Note: this does not update castling rights

Source

pub fn remove(&mut self, sq: SquareCoordinate) -> Result<(), ChessError>

Source

pub fn get_fen(&self) -> Result<String, ChessError>

Source

pub fn load_fen(&mut self, fen: String) -> Result<(), ChessError>

Source

pub fn perft(&mut self, depth: u8, yah: bool) -> Result<u64, ChessError>

Source

pub fn clear(&mut self)

Auto Trait Implementations§

§

impl Freeze for Chess

§

impl RefUnwindSafe for Chess

§

impl Send for Chess

§

impl Sync for Chess

§

impl Unpin for Chess

§

impl UnwindSafe for Chess

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.