xo
Types
The three positions that make up a winning row, column, or diagonal.
pub type Line =
#(Position, Position, Position)
pub type Outcome {
Win(Player, List(Line))
Draw(Player)
Undecided
}
Constructors
-
Win(Player, List(Line))
-
Draw(Player)
-
Undecided
pub type PlayError {
OutOfBounds(Position)
Occupied(Position)
GameAlreadyEnded
}
Constructors
-
OutOfBounds(Position)
-
Occupied(Position)
-
GameAlreadyEnded
pub type Rules {
Rules(winner_plays_first: Bool, take_turns_on_draw: Bool)
}
Constructors
-
Rules(winner_plays_first: Bool, take_turns_on_draw: Bool)
pub type State {
State(first: Player, turn: Player, outcome: Outcome)
}
Constructors
-
State(first: Player, turn: Player, outcome: Outcome)
Constants
pub const default_rules: Rules
The default rules are that the winner plays first and that you must take turns after a draw.
Functions
pub fn get_random_move(
game: Game,
seed: Seed,
) -> Result(#(#(Int, Int), Seed), Nil)
pub fn get_smart_moves(game: Game) -> List(#(Int, Int))
pub fn play_again(game: Game, rules: Rules) -> Game
Reset the game while respecting the given rules.
pub fn start(player: Player) -> Game
Start a new game such that the given player plays first.