Islands.Guesses (Islands Guesses v0.1.39)

Copy Markdown View Source

A guesses struct and functions for the Game of Islands.

The guesses struct contains the fields:

  • hits
  • misses

representing the guesses of an opponent in the Game of Islands.

Based on the book Functional Web Development by Lance Halvorsen.

Summary

Types

t()

A guesses struct for the Game of Islands

Type of guess

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 from guesses's hits.

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

Creates a new guesses struct.

Types

t()

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

A guesses struct for the Game of Islands

type()

@type type() :: :hit | :miss

Type of guess

Functions

add(guesses, type, guess)

@spec 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.

hit_squares(guesses)

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

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

miss_squares(guesses)

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

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

new()

@spec new() :: t()

Creates a new guesses struct.

Examples

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