Sternhalma (Sternhalma v0.1.1) View Source

Link to this section Summary

Functions

Generate an empty board.

Return a list of board cells from one position to another. Returns an empty list if there is no path possible.

Return Hex coordinate for a given pixel coordinate {x, y}.

Return a cell from the game board based on pixel coordinates, x and y. Return nil if the cell does not exist.

Move a marble from one cell on the board to another. The function does not take into account if there is a valid path between the two cells.

Add new marbles to the board.

Return {x, y} pixel coordinates for a given Hex coordinate.

Return the list of unique marbles found on a game board.

Returns the winner, if there is one. To win, all 10 marbles must be in their target positions.

Indicates if all the marbles of the given type are located in their winning locations.

Link to this section Functions

Specs

empty_board() :: Sternhalma.Board.t()

Generate an empty board.

Link to this function

find_path(board, from, to)

View Source

Specs

Return a list of board cells from one position to another. Returns an empty list if there is no path possible.

Specs

from_pixel({number(), number()}) :: Sternhalma.Hex.t()

Return Hex coordinate for a given pixel coordinate {x, y}.

Examples

iex> from_pixel({8.267949192431123, 4.0})
%Sternhalma.Hex{x: 1, y: 3, z: -4}
Link to this function

get_board_cell(board, position)

View Source

Specs

get_board_cell(Sternhalma.Board.t(), {number(), number()}) ::
  {:ok | :error, Sternhalma.Cell.t() | nil}

Return a cell from the game board based on pixel coordinates, x and y. Return nil if the cell does not exist.

Examples

iex> get_board_cell(empty_board(), {17.794, 14.5})
{:ok, %Sternhalma.Cell{marble: nil, position: %Sternhalma.Hex{x: 3, y: -6, z: 3}}}

iex> get_board_cell(empty_board(), {172.794, -104.5})
{:error, nil}
Link to this function

move_marble(board, marble, from, to)

View Source

Specs

Move a marble from one cell on the board to another. The function does not take into account if there is a valid path between the two cells.

Link to this function

setup_marbles(board, marble)

View Source

Specs

setup_marbles(Sternhalma.Board.t(), String.t()) ::
  {:ok, Sternhalma.Board.t()} | {:error, :board_full}

Add new marbles to the board.

The location of the marbles being added is determined based on the number of unique marbles that are already on the board.

Specs

to_pixel(Sternhalma.Hex.t()) :: {number(), number()}

Return {x, y} pixel coordinates for a given Hex coordinate.

Examples

iex> to_pixel(Sternhalma.Hex.new({1, -4, 3}))
{8.267949192431123, 4.0}

Specs

unique_marbles(Sternhalma.Board.t()) :: [String.t()]

Return the list of unique marbles found on a game board.

Specs

winner(Sternhalma.Board.t()) :: String.t() | nil

Returns the winner, if there is one. To win, all 10 marbles must be in their target positions.

Link to this function

won_game?(board, marble)

View Source

Specs

won_game?(Sternhalma.Board.t(), String.t()) :: boolean()

Indicates if all the marbles of the given type are located in their winning locations.