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 Variant for Chess960
impl Variant for Chess960
Source§fn move_piece(&mut self, move_str: &str) -> Result<GameStatus, MoveError>
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 moveErr(MoveError)- An error that indicates that the move is invalid
§Example
let mut variant = Chess960::default();
variant.move_piece("e4").unwrap();Source§fn get_piece_at(&self, pos: Position) -> Option<Piece>
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");Source§fn get_legal_moves(&self, pos: Position) -> Vec<Move>
fn get_legal_moves(&self, pos: Position) -> Vec<Move>
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>
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 fileoverwrite- A boolean that indicates if the file should be overwritten
§Returns
A Result<(), std::io::Error> object
Ok(())- The PGN was saved successfullyErr(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 lost_on_time(&mut self, color: Color)
fn lost_on_time(&mut self, color: Color)
Source§fn get_minified_fen(&self) -> String
fn get_minified_fen(&self) -> String
Source§fn get_last_move(&self) -> Option<Move>
fn get_last_move(&self) -> Option<Move>
Source§fn is_white_turn(&self) -> bool
fn is_white_turn(&self) -> bool
Source§fn get_halfmove_clock(&self) -> u32
fn get_halfmove_clock(&self) -> u32
Source§fn get_fullmove_number(&self) -> u32
fn get_fullmove_number(&self) -> u32
Source§fn get_castling_rights(&self) -> String
fn get_castling_rights(&self) -> String
Source§fn get_en_passant(&self) -> Option<Position>
fn get_en_passant(&self) -> Option<Position>
Source§fn get_starting_fen(&self) -> String
fn get_starting_fen(&self) -> String
Source§fn get_status(&self) -> GameStatus
fn get_status(&self) -> GameStatus
Source§impl VariantBuilder for Chess960
impl VariantBuilder for Chess960
Source§fn from_fen(fen: &str) -> Result<Chess960, FenError>
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 stateErr(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>
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 stateErr(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>
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 stateErr(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>
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 stateErr(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();