Islands.State (Islands State v0.1.13) View Source

Implements a state machine for the Game of Islands.

Based on the book Functional Web Development by Lance Halvorsen.

Link to this section Summary

Functions

Callback implementation for Access.fetch/2.

Callback implementation for Access.pop/2.

Link to this section Types

Specs

game_state() ::
  :initialized | :players_set | :player1_turn | :player2_turn | :game_over

Specs

player_state() :: :islands_not_set | :islands_set

Specs

request() ::
  :add_player
  | {:position_island, Islands.PlayerID.t()}
  | {:position_all_islands, Islands.PlayerID.t()}
  | {:set_islands, Islands.PlayerID.t()}
  | {:guess_coord, Islands.PlayerID.t()}
  | {:stop, Islands.PlayerID.t()}
  | {:win_check, :no_win | :win}

Specs

t() :: %Islands.State{
  game_state: game_state(),
  player1_state: player_state(),
  player2_state: player_state()
}

Link to this section Functions

Specs

check(t(), request()) :: {:ok, t()} | :error

Callback implementation for Access.fetch/2.

Link to this function

get_and_update(state, key, fun)

View Source

Callback implementation for Access.get_and_update/3.

Specs

new() :: t()

Callback implementation for Access.pop/2.