Game

Trait Game 

Source
pub trait Game {
    type Move: Copy;
    type Iter: Iterator<Item = Self::Move>;

    // Required methods
    fn player(&self) -> Player;
    fn score(&self) -> u32;
    fn max_score(&self) -> u32;
    fn min_score(&self) -> i32;
    fn make_move(&mut self, m: Self::Move) -> bool;
    fn possible_moves(&self) -> Self::Iter;
    fn is_winning_move(&self, m: Self::Move) -> bool;
}
Expand description

Represents a combinatorial game.

Required Associated Types§

Source

type Move: Copy

The type of move this game uses.

Source

type Iter: Iterator<Item = Self::Move>

The iterator type for possible moves.

Required Methods§

Source

fn player(&self) -> Player

Returns the player whose turn it is.

Source

fn score(&self) -> u32

Scores a position. The default implementation uses the size minus the number of moves (for finite games)

Source

fn max_score(&self) -> u32

Get the max score of a game.

Source

fn min_score(&self) -> i32

Get the min score of a game. This should be negative.

Source

fn make_move(&mut self, m: Self::Move) -> bool

Returns true if the move was valid, and makes the move if it was.

Source

fn possible_moves(&self) -> Self::Iter

Returns a vector of all possible moves.

If possible, this function should “guess” what the best moves are first. For example, if this is for tic tac toe, it should give the middle move first. This allows alpha-beta pruning to move faster.

Source

fn is_winning_move(&self, m: Self::Move) -> bool

Returns true if the move is a winning move.

Implementors§