Skip to main content

Chess960

Struct Chess960 

Source
pub struct Chess960 { /* private fields */ }
Expand description

Chess960 is a variant of chess that uses the same rules as standard chess, but the starting position of the pieces is randomized.

§Attributes

  • game - The Game struct that contains the current state of the game

Trait Implementations§

Source§

impl Clone for Chess960

Source§

fn clone(&self) -> Chess960

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Chess960

Source§

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

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

impl Default for Chess960

Source§

fn default() -> Chess960

Generates a random starting position for the pieces

§Returns

A Chess960 struct with a random starting position

§Example
let variant = Chess960::default();
Source§

impl Variant for Chess960

Source§

fn move_piece(&mut self, move_str: &str) -> Result<GameStatus, MoveError>

Moves a piece on the board

§Arguments
  • move_str - The move string that represents the move to be made
§Returns

A Result<GameStatus, MoveError> object

  • Ok(GameStatus) - The status of the game after the move
  • Err(MoveError) - An error that indicates that the move is invalid
§Example
let mut variant = Chess960::default();
variant.move_piece("e4").unwrap();
Source§

fn undo(&mut self)

Undoes the last Move made

§Example
let mut variant = Chess960::default();
variant.move_piece("e4").unwrap();
variant.undo();
Source§

fn redo(&mut self)

Redoes the last Move that was undone

§Example
let mut variant = Chess960::default();
variant.move_piece("e4").unwrap();
variant.undo();
variant.redo();
Source§

fn pgn(&self) -> String

Returns the PGN string of the game

§Returns

A string with the PGN of the game

§Example
let variant = Chess960::default();
let pgn = variant.pgn();
Source§

fn fen(&self) -> String

Returns the FEN string of the Game

§Returns

A string with the FEN of the Game

§Example

let variant = Chess960::default();
let fen = variant.fen();
Source§

fn get_piece_at(&self, pos: Position) -> Option<Piece>

Returns the piece at a given position

§Arguments
  • pos - The position to get the piece from
§Returns

The piece at the given position, if there is one

§Example
use chess_lab::core::Position;

let variant = Chess960::default();
let piece = variant.get_piece_at(Position::from_string("e2").unwrap());
assert!(piece.is_some());
assert_eq!(piece.unwrap().to_string(), "P");

Returns the legal moves of a piece at a given position

§Arguments
  • pos - The position to get the legal moves from
§Returns

A vector with the legal moves of the piece at the given position

§Example
use chess_lab::core::Position;

let variant = Chess960::default();
let legal_moves = variant.get_legal_moves(Position::from_string("e2").unwrap());
assert!(legal_moves.iter().any(|m| m.to_string() == "e4"));
Source§

fn save(&self, path: &str, overwrite: bool) -> Result<(), Error>

Saves the PGN string of the Game to a file

§Arguments
  • path - The path to the file
  • overwrite - A boolean that indicates if the file should be overwritten
§Returns

A Result<(), std::io::Error> object

  • Ok(()) - The PGN was saved successfully
  • Err(std::io::Error) - An error that indicates that the PGN could not be saved
§Example

let variant = Chess960::default();
variant.save("data/chess960/ex.pgn", true).unwrap();
Source§

fn resign(&mut self, color: Color)

Resigns the Game for a Color

§Arguments
  • color - The color that resigns
§Example
use chess_lab::core::Color;

let mut variant = Chess960::default();
variant.resign(Color::White);
Source§

fn draw(&mut self)

Sets the Game as a draw

§Example
let mut variant = Chess960::default();
variant.draw();
Source§

fn lost_on_time(&mut self, color: Color)

Sets the game lost in time for a Color

§Arguments
  • color - The Color that lost in time
§Example
use chess_lab::core::Color;

let mut variant = Chess960::default();
variant.lost_on_time(Color::White);
Source§

fn get_minified_fen(&self) -> String

Returns the minified FEN string of the Game

§Returns

A string with the minified FEN of the Game

§Example
let variant = Chess960::default();
let minified_fen = variant.get_minified_fen();
Source§

fn get_last_move(&self) -> Option<Move>

Returns the last Move of the Game

§Returns

The last Move of the Game, if there is one

§Examples
let mut game = StandardChess::default();
game.move_piece("e4").unwrap();
let last_move = game.get_last_move();
assert_eq!(last_move.unwrap().to_string(), "e4");
Source§

fn is_white_turn(&self) -> bool

Returns whether it is white’s turn to move

§Returns

Whether it is white’s turn to move

§Examples
let game = Chess960::default();
let color = game.is_white_turn();
Source§

fn get_halfmove_clock(&self) -> u32

Returns the halfmove clock of the Game

§Returns

The halfmove clock of the Game

§Examples
let game = Chess960::default();
let halfmove_clock = game.get_halfmove_clock();
Source§

fn get_fullmove_number(&self) -> u32

Returns the fullmove number of the Game

§Returns

The fullmove number of the Game

§Examples
let game = Chess960::default();
let fullmove_number = game.get_fullmove_number();
Source§

fn get_castling_rights(&self) -> String

Returns the current castling rights of the Game

§Returns

The current castling rights of the Game

§Examples
let game = Chess960::default();
let castling_rights = game.get_castling_rights();
Source§

fn get_en_passant(&self) -> Option<Position>

Returns the en passant square of the Game

§Returns

The en passant square of the Game

§Examples
let game = Chess960::default();
let en_passant = game.get_en_passant();
Source§

fn get_starting_fen(&self) -> String

Returns the starting FEN of the Game

§Returns

A copy of the starting FEN of the Game

§Examples
let game = Chess960::default();
let starting_fen = game.get_starting_fen();
Source§

fn get_status(&self) -> GameStatus

Returns the status of the Game

§Returns

The status of the Game

§Examples

let game = Chess960::default();
let status = game.get_status();
Source§

impl VariantBuilder for Chess960

Source§

fn name() -> &'static str

Returns the name of the Variant

§Returns

A string with the name of the Variant

§Example
let name = Chess960::name();
assert_eq!(name, "Chess960");
Source§

fn new(game: Game) -> Chess960

Returns a new instance of the variant from a Game struct

§Arguments
  • game - The Game struct that contains the current state of the game
§Returns

A Chess960 struct with the game state

§Example
use chess_lab::logic::Game;

let game = Game::default();
let variant = Chess960::new(game);
Source§

fn from_fen(fen: &str) -> Result<Chess960, FenError>

Returns a new instance of the variant from a FEN string

§Arguments
  • fen - The FEN string that represents the game state
§Returns

A Result<Chess960, FenError> object

  • Ok(Chess960) - A Chess960 struct with the game state
  • Err(FenError) - An error that indicates that the FEN string is invalid
§Example
let fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
let variant = Chess960::from_fen(fen).unwrap();
Source§

fn from_pgn(pgn: &str) -> Result<Chess960, PGNError>

Returns a new instance of the variant from a PGN string

§Arguments
  • pgn - The PGN string that represents the game state
§Returns

A Result<Chess960, PgnError> object

  • Ok(Chess960) - A Chess960 struct with the game state
  • Err(PgnError) - An error that indicates that the PGN string is invalid
§Example
let pgn = "[Variant \"Chess960\"]\n1. e4 e5 2. Nf3 Nc6";
let variant = Chess960::from_pgn(pgn).unwrap();
Source§

fn load(path: &str) -> Result<Chess960, PGNError>

Loads a new instance of the variant from a PGN file

§Arguments
  • path - The path to the PGN file
§Returns

A Result<Chess960, PgnError> object

  • Ok(Chess960) - A Chess960 struct with the game state
  • Err(PgnError) - An error that indicates that the PGN file is invalid
§Example
let path = "data/chess960/ex1.pgn";
let variant = Chess960::load(path).unwrap();
Source§

fn load_all(path: &str) -> Result<Vec<Chess960>, PGNError>

Loads all the instances of the variant from a PGN file

§Arguments
  • path - The path to the PGN file
§Returns

A Result<Vec<Chess960>, PgnError> object

  • Ok(Vec<Chess960>) - A vector with all the Chess960 structs with the game state
  • Err(PgnError) - An error that indicates that the PGN file is invalid
§Example
let path = "data/chess960/ex2.pgn";
let variants = Chess960::load_all(path).unwrap();

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V