View Source Islands.Board (Islands Board v0.1.26)
A board struct and functions for the Game of Islands.
The board struct contains the fields islands
and misses
representing the
characteristics of a board in the Game of Islands.
Based on the book Functional Web Development by Lance Halvorsen.
Link to this section Summary
Functions
Checks if all islands have been positioned on board
.
Returns a list of island types for forested islands.
Returns a map assigning the CSS grid position of each island
on board
to its island type.
Checks if guess
hit any island on board
and returns a response tuple.
Returns a map assigning the list of hits "cells" of each island
on board
to its island type.
Returns the board
's total number of hits.
Returns a map assigning to :squares the list of square numbers
from the board
's misses.
Returns the board
's total number of misses.
Returns an empty board struct.
Positions island
on board
and returns an updated board
or
{:error, reason}
if island
overlaps another board
's island.
Link to this section Types
Specs
islands() :: %{required(Islands.Island.type()) => Islands.Island.t()}
A map assigning islands to their island types
Specs
t() :: %Islands.Board{islands: islands(), misses: Islands.Island.coords()}
A board struct for the Game of Islands
Link to this section Functions
Specs
Checks if all islands have been positioned on board
.
Specs
forested_types(t()) :: [Islands.Island.type()]
Returns a list of island types for forested islands.
Specs
grid_positions(t()) :: %{ required(Islands.Island.type()) => Islands.Island.grid_position() }
Returns a map assigning the CSS grid position of each island
on board
to its island type.
Specs
guess(t(), Islands.Coord.t()) :: Islands.Board.Response.t()
Checks if guess
hit any island on board
and returns a response tuple.
Specs
hit_cells(t()) :: %{ required(Islands.Island.type()) => [Islands.Island.grid_cell()] }
Returns a map assigning the list of hits "cells" of each island
on board
to its island type.
Specs
hits(t()) :: non_neg_integer()
Returns the board
's total number of hits.
Specs
miss_squares(t()) :: %{squares: [Islands.Coord.square()]}
Returns a map assigning to :squares the list of square numbers
from the board
's misses.
Specs
misses(t()) :: non_neg_integer()
Returns the board
's total number of misses.
Specs
new() :: t()
Returns an empty board struct.
Specs
position_island(t(), Islands.Island.t()) :: t() | {:error, atom()}
Positions island
on board
and returns an updated board
or
{:error, reason}
if island
overlaps another board
's island.