pub struct StandardChess { /* private fields */ }Expand description
Standard Chess Variant This Variant is the most common chess variant played worldwide It is played on an 8x8 board with the following pieces for each player:
- 8 Pawns
- 2 Rooks
- 2 Knights
- 2 Bishops
- 1 Queen
- 1 King
The game is won by checkmating the opponent’s king The game is drawn by stalemate, threefold repetition, the fifty-move rule, or agreement The game is lost by resigning or losing on time
§Attributes
game- The game struct that holds the state of the game
Trait Implementations§
Source§impl Clone for StandardChess
impl Clone for StandardChess
Source§fn clone(&self) -> StandardChess
fn clone(&self) -> StandardChess
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StandardChess
impl Debug for StandardChess
Source§impl Default for StandardChess
impl Default for StandardChess
Source§fn default() -> StandardChess
fn default() -> StandardChess
Creates a new instance of the StandardChess Variant with default values
§Returns
A new instance of the StandardChess Variant
§Examples
let game = StandardChess::default();Source§impl Variant for StandardChess
impl Variant for StandardChess
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 crate::logic::Board
§Arguments
move_str- A move string in algebraic notation.
§Returns
A Result<GameStatus, MoveError> object
Ok(GameStatus)- The status of the game after the move.Err(MoveError)- An error occurred while moving the piece.
§Examples
let mut game = StandardChess::default();
let status = game.move_piece("e4");
assert_eq!(status, Ok(GameStatus::InProgress));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 game = StandardChess::default();
let piece = game.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 for
§Returns
A vector of legal moves for the piece at the given position
§Example
use chess_lab::core::Position;
let game = StandardChess::default();
let legal_moves = game.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 Game to a file
§Arguments
path- The path to the fileoverwrite- Whether to overwrite the file if it already exists
§Returns
A Result<(), std::io::Error> object
Ok(())- The game was saved successfullyErr(std::io::Error)- An error occurred while saving the game
§Examples
let game = StandardChess::default();
let path = "data/standard/ex.pgn";
game.save(path, 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 StandardChess
impl VariantBuilder for StandardChess
Source§fn new(game: Game) -> StandardChess
fn new(game: Game) -> StandardChess
Creates a new instance of the StandardChess Variant
§Returns
A new instance of the StandardChess Variant
§Examples
use chess_lab::logic::Game;
let game = StandardChess::new(Game::default());Source§fn from_fen(fen: &str) -> Result<StandardChess, FenError>
fn from_fen(fen: &str) -> Result<StandardChess, FenError>
Creates a new instance of the StandardChess Variant from a FEN string
§Arguments
fen- A FEN string
§Returns
Ok(StandardChess)- A new instance of the StandardChess VariantErr(FenError)- An error occurred while parsing the FEN string
§Examples
let fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
let game = StandardChess::from_fen(fen).unwrap();Source§fn from_pgn(pgn: &str) -> Result<StandardChess, PGNError>
fn from_pgn(pgn: &str) -> Result<StandardChess, PGNError>
Creates a new instance of the StandardChess Variant from a PGN string
§Arguments
pgn- A PGN string
§Returns
A Result<StandardChess, PGNError> object
Ok(StandardChess)- A new instance of the StandardChess VariantErr(PgnError)- An error occurred while parsing the PGN string
§Examples
let pgn = "1. e4 e5 2. Nf3 Nc6 3. Bb5 a6";
let game = StandardChess::from_pgn(pgn).unwrap();Source§fn load(path: &str) -> Result<StandardChess, PGNError>
fn load(path: &str) -> Result<StandardChess, PGNError>
Loads the Game from a file
§Arguments
path- The path to the file
§Returns
A Result<StandardChess, PGNError> object
Ok(StandardChess)- The Game was loaded successfullyErr(PgnError)- An error occurred while loading the Game
§Examples
let path = "data/standard/ex1.pgn";
let game = StandardChess::load(path).unwrap();Source§fn load_all(path: &str) -> Result<Vec<Self>, PGNError>
fn load_all(path: &str) -> Result<Vec<Self>, PGNError>
Loads multiple Games from a file
§Arguments
path- The path to the file
§Returns
A Result<Vec<StandardChess>, PGNError> object
Ok(Vec<StandardChess>)- The games were loaded successfullyErr(PgnError)- An error occurred while loading the games
§Examples
let path = "data/standard/ex3.pgn";
let games = StandardChess::load_all(path).unwrap();