# `Islands.State`
[🔗](https://github.com/RaymondLoranger/islands_state/blob/main/lib/islands/state.ex#L4)

A state struct and functions for the _Game of Islands_.

The state struct contains the fields:

  - `game_state`
  - `player1_state`
  - `player2_state`

allowing the implementation of a state machine in the _Game of Islands_.

##### Based on the book [Functional Web Development](https://pragprog.com/titles/lhelph/functional-web-development-with-elixir-otp-and-phoenix/) by Lance Halvorsen.

# `event`

```elixir
@type event() ::
  :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}
```

State machine event

# `game_state`

```elixir
@type game_state() ::
  :initialized | :players_set | :player1_turn | :player2_turn | :game_over
```

Game state

# `player_state`

```elixir
@type player_state() :: :islands_not_set | :islands_set
```

Player state

# `t`

```elixir
@type t() :: %Islands.State{
  game_state: game_state(),
  player1_state: player_state(),
  player2_state: player_state()
}
```

A state struct for the Game of Islands

# `check`

```elixir
@spec check(t(), event()) :: {:ok, t()} | :error
```

Decides whether to permit the `state`/`event` combination. Also decides
whether to transition to a new state. Returns `{:ok, new_state}` if the
combination is permissible. Returns `:error` if it is not.

# `fetch`

# `get_and_update`

# `new`

```elixir
@spec new() :: t()
```

Creates a new state struct.

## Examples

    iex> Islands.State.new()
    %Islands.State{
      game_state: :initialized,
      player1_state: :islands_not_set,
      player2_state: :islands_not_set
    }

# `pop`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
