View Source Hanoi.TowerGame (Towers of Hanoi v1.0.0)
The Hanoi game as a public API & state.
Runs as a supervisor and starts a GenServer to process work and an ETS instance to hold state. Usually run as part of an OTP application.
Instances are removed by an independent periodic purger process.
Summary
Functions
Functions that adds another game A game is an ETS table and a genserver under supervision
Returns a specification to start this module under a supervisor.
Functions that returns how many games are currently running
Function that terminates a session. Called by Session Purger for games where no move has been made for a while
Function returning the current state of the hanoi board
Debug function returning current state of hanoi board in a textual representation.
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.
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
Functions that returns information on the games currently running
Call this function to start up the module. Name and Stones must be provided.
Functions
@spec add_game(name :: atom(), stones :: pos_integer()) :: atom() | tuple()
Functions that adds another game A game is an ETS table and a genserver under supervision
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec count_games() :: non_neg_integer()
Functions that returns how many games are currently running
@spec delete_game(pid :: pid()) :: :ok | {:error, :not_found}
Function that terminates a session. Called by Session Purger for games where no move has been made for a while
@spec get_board_state(name :: atom()) :: Hanoi.Board.t()
Function returning the current state of the hanoi board
Debug function returning current state of hanoi board in a textual representation.
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
@spec get_number_moves(name :: atom()) :: non_neg_integer()
Function returning the number of moves that have been played.
@spec get_number_stones(name :: atom()) :: non_neg_integer()
Function that returns the number of stones on the board.
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.
@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 show_games_state() :: Keyword.t()
Functions that returns information on the games currently running
[
[class: Hanoi.TowerState, name: :Hanoi_91924B39, pid: #PID<0.486.0>, stones: 7, moves: 0, age: 152],
[class: Hanoi.TowerState, name: :Hanoi_31148637, pid: #PID<0.515.0>, stones: 6, moves: 32, age: 83]
]
Call this function to start up the module. Name and Stones must be provided.