Skip to main content

Variant

Trait Variant 

Source
pub trait Variant {
Show 20 methods // Required methods fn move_piece(&mut self, move_str: &str) -> Result<GameStatus, MoveError>; fn undo(&mut self); fn redo(&mut self); fn pgn(&self) -> String; fn fen(&self) -> String; fn get_piece_at(&self, pos: Position) -> Option<Piece>; fn get_legal_moves(&self, pos: Position) -> Vec<Move>; fn save(&self, path: &str, overwrite: bool) -> Result<(), Error>; fn resign(&mut self, color: Color); fn draw(&mut self); fn lost_on_time(&mut self, color: Color); fn get_minified_fen(&self) -> String; fn get_last_move(&self) -> Option<Move>; fn is_white_turn(&self) -> bool; fn get_halfmove_clock(&self) -> u32; fn get_fullmove_number(&self) -> u32; fn get_castling_rights(&self) -> String; fn get_en_passant(&self) -> Option<Position>; fn get_starting_fen(&self) -> String; fn get_status(&self) -> GameStatus;
}
Expand description

A trait for a chess variant.

A chess variant is a game that is derived from chess, but has different rules.

Required Methods§

Source

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

Moves a piece on the 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.
Source

fn undo(&mut self)

Undoes the last move.

Source

fn redo(&mut self)

Redoes the last undone move.

Source

fn pgn(&self) -> String

Returns the PGN string of the game.

§Returns

The PGN string of the game.

Source

fn fen(&self) -> String

Returns the FEN string of the game.

§Returns

The FEN string of the game.

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.

Returns the legal moves for a given position.

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

A vector of legal moves for the given position.

Source

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

Saves the game to a file.

§Arguments
  • path - The path to the file.
  • overwrite - Whether to overwrite the file if it already exists.
§Returns

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

  • Ok(()) - The game was saved successfully.
  • Err(std::io::Error) - An error occurred while saving the game.
Source

fn resign(&mut self, color: Color)

Resigns the game for a player.

§Arguments
  • color - The color of the player that is resigning.
Source

fn draw(&mut self)

Sets the game as a draw by agreement.

Source

fn lost_on_time(&mut self, color: Color)

Sets the game as lost in time for a player.

§Arguments
  • color - The color of the player that lost in time.
Source

fn get_minified_fen(&self) -> String

Gets the minified fen of the game.

§Returns

The minified fen of the game.

Source

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

Gets the last move of the game.

§Returns

The last move of the game, if there is one.

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.

Source

fn get_halfmove_clock(&self) -> u32

Returns the halfmove clock of the game.

§Returns

The halfmove clock of the game.

Source

fn get_fullmove_number(&self) -> u32

Returns the fullmove number of the game.

§Returns

The fullmove number of the game.

Source

fn get_castling_rights(&self) -> String

Returns the castling rights of the game.

§Returns

The castling rights of the game.

Source

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

Returns the en passant square of the game.

§Returns

The en passant square of the game.

Source

fn get_starting_fen(&self) -> String

Returns the starting FEN of the game.

§Returns

The starting FEN of the game.

Source

fn get_status(&self) -> GameStatus

Returns the status of the game.

§Returns

The status of the game.

Implementors§