pub trait Position: Sized {
    type Move: Eq + Clone + Debug;
    type ReverseMove;
    type Settings: Default;

    // Required methods
    fn start_position_with_settings(settings: &Self::Settings) -> Self;
    fn side_to_move(&self) -> Color;
    fn generate_moves<E: Extend<Self::Move>>(&self, moves: &mut E);
    fn do_move(&mut self, mv: Self::Move) -> Self::ReverseMove;
    fn reverse_move(&mut self, mv: Self::ReverseMove);
    fn game_result(&self) -> Option<GameResult>;

    // Provided methods
    fn start_position() -> Self { ... }
    fn move_is_legal(&self, mv: Self::Move) -> bool { ... }
}
Expand description

The simplest abstract representation of a game position. Together, the provided methods encode all the rules of the game.

Required Associated Types§

source

type Move: Eq + Clone + Debug

The type for moves in the game.

source

type ReverseMove

The type for a reverse move in the game.

source

type Settings: Default

Optional Settings when initializing the position.

Required Methods§

source

fn start_position_with_settings(settings: &Self::Settings) -> Self

Returns the starting position for the game with the given settings.

source

fn side_to_move(&self) -> Color

Returns the side to move for the current position.

source

fn generate_moves<E: Extend<Self::Move>>(&self, moves: &mut E)

Generates all legal moves for the side to move, and extends the provided data structure with them.

source

fn do_move(&mut self, mv: Self::Move) -> Self::ReverseMove

Plays a move in the position. Also returns an ReverseMove do take the move back.

Doing and then undoing a move always restores the position to exactly the same state.

source

fn reverse_move(&mut self, mv: Self::ReverseMove)

Reverse a move made by do_move.

Doing and then undoing a move always restores the position to exactly the same state.

source

fn game_result(&self) -> Option<GameResult>

Returns the result if the game is decided, otherwise returns None. If the winning player always plays the last move (as in chess), implementations are allowed to only return a win when the losing player is to move.

Provided Methods§

source

fn start_position() -> Self

Returns the starting position for the game. This function always produces identical values.

Checks if a move is legal in the current position. Enables minimax algorithms to use the killer-move heuristic in their search.

Object Safety§

This trait is not object safe.

Implementors§