View Source Hanoi.TowerState (Towers of Hanoi v1.0.0)

Private API: GenServer providing the business logic for the game. Created by TowerGame along with ETS table to hold state.

Summary

Functions

Returns a specification to start this module under a supervisor.

Function returning the current state of the hanoi board

Debug function returning current state of hanoi board in a textual representation.

Returns the current state of the game, board, moves etc.

Function that for a board with all stones on left pile will move them in a legal way (no big stone on small stone) to the right hand pile

Function returning the number of moves that have been played.

Function that returns the number of stones on the board.

Completes work of init asynchronously

Sets up basic state. Most of work completed in continuation asynchronously.

Funtion returns true if game is complete That is all stones in correct order on right hand pile

Funtion that moves a stone between piles. Will error if the stone is bigger than the one at the top of the pile. Increments moves taken.

Restarts a game with a new number of stones on the board. Resets move count

Call this function to start up the module. Name and Stones must be provided.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec get_board_state(name :: atom()) :: Hanoi.Board.t()

Function returning the current state of the hanoi board

Link to this function

get_board_state_as_text(server)

View Source
@spec get_board_state_as_text(name :: atom()) :: String.t()

Debug function returning current state of hanoi board in a textual representation.

@spec get_game_state(name :: atom()) :: tuple()

Returns the current state of the game, board, moves etc.

Link to this function

get_moves_to_win(server)

View Source
@spec get_moves_to_win(name :: atom()) :: list() | :error

Function that for a board with all stones on left pile will move them in a legal way (no big stone on small stone) to the right hand pile

Link to this function

get_number_moves(server)

View Source
@spec get_number_moves(name :: atom()) :: non_neg_integer()

Function returning the number of moves that have been played.

Link to this function

get_number_stones(server)

View Source
@spec get_number_stones(name :: atom()) :: non_neg_integer()

Function that returns the number of stones on the board.

Link to this function

handle_call(msg, arg2, state)

View Source

Handles events

Link to this function

handle_continue(atom, data)

View Source

Completes work of init asynchronously

Sets up basic state. Most of work completed in continuation asynchronously.

@spec is_complete(name :: atom()) :: boolean() | :error

Funtion returns true if game is complete That is all stones in correct order on right hand pile

Link to this function

move_stone(server, from, to)

View Source
@spec move_stone(name :: atom(), from :: atom(), to :: atom()) :: :ok | :error

Funtion that moves a stone between piles. Will error if the stone is bigger than the one at the top of the pile. Increments moves taken.

Link to this function

reset_game(server, new_stones)

View Source
@spec reset_game(name :: atom(), new_stones :: pos_integer()) :: :ok

Restarts a game with a new number of stones on the board. Resets move count

@spec start_link(opts :: list()) :: {:error, any()} | {:ok, pid()}

Call this function to start up the module. Name and Stones must be provided.