Trait board_game_traits::Position
source · 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§
sourcetype ReverseMove
type ReverseMove
The type for a reverse move in the game.
Required Methods§
sourcefn start_position_with_settings(settings: &Self::Settings) -> Self
fn start_position_with_settings(settings: &Self::Settings) -> Self
Returns the starting position for the game with the given settings.
sourcefn side_to_move(&self) -> Color
fn side_to_move(&self) -> Color
Returns the side to move for the current position.
sourcefn generate_moves<E: Extend<Self::Move>>(&self, moves: &mut E)
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.
sourcefn do_move(&mut self, mv: Self::Move) -> Self::ReverseMove
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.
sourcefn reverse_move(&mut self, mv: Self::ReverseMove)
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.
sourcefn game_result(&self) -> Option<GameResult>
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§
sourcefn start_position() -> Self
fn start_position() -> Self
Returns the starting position for the game. This function always produces identical values.
sourcefn move_is_legal(&self, mv: Self::Move) -> bool
fn move_is_legal(&self, mv: Self::Move) -> bool
Checks if a move is legal in the current position. Enables minimax algorithms to use the killer-move heuristic in their search.