Struct w_chess::Chessboard

source ·
pub struct Chessboard {
    pub history: Vec<ChessMove>,
    /* private fields */
}

Fields§

§history: Vec<ChessMove>

Implementations§

source§

impl Chessboard

source

pub fn new() -> Self

Returns a chessboard with the starting position.

§Examples
use w_chess::Chessboard;
let mut board = Chessboard::new();
board.move_to("e4");
source

pub fn from_fen(fen: &str) -> Self

Returns a chessboard with the position from the FEN string.

§Examples
use w_chess::Chessboard;
let mut board = Chessboard::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
board.move_to("e4");
source

pub fn get_fen(&self) -> String

Returns the FEN string of the current position.

§Examples
use w_chess::Chessboard;
let board = Chessboard::new();
assert_eq!(board.get_fen(), "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
source

pub fn is_checked(&self, color: bool) -> bool

Returns if the current position is checked.

§Examples
use w_chess::Chessboard;
let board = Chessboard::new();
assert_eq!(board.is_checked(true), false);
source

pub fn is_mate(&self, color: bool) -> bool

Returns if the current position is a checkmate.

§Examples
use w_chess::Chessboard;
let board = Chessboard::new();
assert_eq!(board.is_mate(true), false);
source

pub fn is_stalemate(&self, color: bool) -> bool

Returns if the current position is a stalemate.

§Examples
use w_chess::Chessboard;
let board = Chessboard::new();
assert_eq!(board.is_stalemate(true), false);
source

pub fn is_fifty_moves(&self) -> bool

Returns if the current position is a fifty moves rule.

§Examples
use w_chess::Chessboard;
let board = Chessboard::new();
assert_eq!(board.is_fifty_moves(), false);
source

pub fn is_threefold_repetition(&self) -> bool

Returns if the current position is a threefold repetition.

§Examples
use w_chess::Chessboard;
let board = Chessboard::new();
assert_eq!(board.is_threefold_repetition(), false);
``
source

pub fn move_to(&mut self, san: &str)

Moves a piece to the given square in SAN format.

§Examples
use w_chess::Chessboard;
let mut board = Chessboard::new();
board.move_to("e4");
source

pub fn ascii(&self) -> String

Returns the ASCII representation of the current position.

§Examples
use w_chess::Chessboard;
let board = Chessboard::new();
println!("{}", board.ascii());

Trait Implementations§

source§

impl Debug for Chessboard

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Chessboard

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.