Islands.Island (Islands Island v0.1.17) 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
Specs
coords() :: MapSet.t(Islands.Coord.t())
Specs
t() :: %Islands.Island{ coords: coords(), hits: coords(), origin: Islands.Coord.t(), type: type() }
Specs
type() :: :atoll | :dot | :l_shape | :s_shape | :square
Link to this section Functions
Specs
Specs
Specs
guess(t(), Islands.Coord.t()) :: {:hit, t()} | :miss
Specs
hit_cells(t()) :: [<<_::2, _::_*8>>]
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"]
Specs
new(type(), Islands.Coord.t()) :: {:ok, t()} | {:error, atom()}