xo

Types

pub opaque type Game

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 Player {
  X
  O
}

Constructors

  • X
  • O
pub type Position =
  #(Int, Int)
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)
pub type Tile =
  Option(Player)

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 map(
  game: Game,
  f: fn(#(Int, Int), Option(Player)) -> a,
) -> List(a)
pub fn next_turn(player: Player) -> Player
pub fn play(
  game: Game,
  pos: #(Int, Int),
) -> Result(Game, PlayError)
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.

pub fn to_state(game: Game) -> State
pub fn to_string(game: Game) -> String
Search Document