Islands.Guesses (Islands Guesses v0.1.21) View Source

A guesses struct and functions for the Game of Islands.

The guesses struct contains the fields hits and misses classifying a player's guesses in the Game of Islands.

Based on the book Functional Web Development by Lance Halvorsen.

Link to this section Summary

Functions

Adds a hit guess to the :hits set or a miss guess to the :misses set.

Returns a map assigning to :squares the list of square numbers for the guesses's hits.

Returns a map assigning to :squares the list of square numbers for the guesses's misses.

Creates a new guesses struct.

Link to this section Types

Specs

t() :: %Islands.Guesses{
  hits: Islands.Island.coords(),
  misses: Islands.Island.coords()
}

Specs

type() :: :hit | :miss

Link to this section Functions

Link to this function

add(guesses, type, guess)

View Source

Specs

add(t(), type(), Islands.Coord.t()) :: t() | {:error, atom()}

Adds a hit guess to the :hits set or a miss guess to the :misses set.

Specs

hit_squares(t()) :: %{squares: [Islands.Coord.square()]}

Returns a map assigning to :squares the list of square numbers for the guesses's hits.

Specs

miss_squares(t()) :: %{squares: [Islands.Coord.square()]}

Returns a map assigning to :squares the list of square numbers for the guesses's misses.

Specs

new() :: t()

Creates a new guesses struct.

Examples

iex> Islands.Guesses.new()
%Islands.Guesses{
  hits: MapSet.new(),
  misses: MapSet.new()
}