Islands Island v0.1.10 Islands.Island View Source
Models an island
in the Game of Islands.
Based on the book Functional Web Development by Lance Halvorsen.
Link to this section Summary
Functions
Returns a list of hit "cells".
Link to this section Types
Link to this type
t()
View Sourcet() :: %Islands.Island{ coords: coords(), hits: coords(), origin: Islands.Coord.t(), type: type() }
Link to this section Functions
Link to this function
guess(island, guess)
View Sourceguess(t(), Islands.Coord.t()) :: {:hit, t()} | :miss
Returns a list of hit "cells".
Examples
iex> alias Islands.{Coord, Island}
iex> {:ok, origin} = Coord.new(1, 1)
iex> {:ok, atoll} = Island.new(:atoll, origin)
iex> {:ok, b1} = Coord.new(1, 2)
iex> {:ok, a3} = Coord.new(3, 1)
iex> {:hit, atoll} = Island.guess(atoll, b1)
iex> {:hit, atoll} = Island.guess(atoll, a3)
iex> Island.hit_cells(atoll) |> Enum.sort()
["a3", "b1"]
Link to this function
new(type, origin)
View Sourcenew(type(), Islands.Coord.t()) :: {:ok, t()} | {:error, atom()}