Sternhalma.Board (Sternhalma v0.1.1) View Source

Provides functions to manipulate the Chinese Checkers game board.

Link to this section Summary

Functions

Generate an empty board.

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

Fill in a home triangle with marbles.

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

Link to this section Types

Specs

home_triangle() ::
  :top_left | :top | :top_right | :bottom_left | :bottom | :bottom_right

Specs

t() :: [Sternhalma.Cell.t()]

Link to this section Functions

Link to this function

bottom_right_positions()

View Source

Specs

count_marbles(t()) :: number()

Specs

empty() :: t()

Generate an empty board.

Link to this function

get_board_cell(board, pixel_coord)

View Source

Specs

get_board_cell(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(), {17.794, 14.5})
{:ok, %Sternhalma.Cell{marble: nil, position: %Sternhalma.Hex{x: 3, y: -6, z: 3}}}

iex> get_board_cell(empty(), {172.794, -104.5})
{:error, nil}

Specs

position_opponent(0..5) :: {:ok, home_triangle()} | {:error, nil}
Link to this function

setup_triangle(board, atom, marble)

View Source

Specs

setup_triangle(t(), home_triangle(), String.t()) :: t()

Fill in a home triangle with marbles.

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