GameApp.Games.TicTacToe.WithAgent (game_app v0.1.0)
A module to handle the Tic Tac Toe game logic and state management using an Agent.
Summary
Functions
Returns a specification to start this module under a supervisor.
Crashes the Agent intentionally for testing purposes.
Retrieves the current state of the game.
Returns the initial state of the Tic Tac Toe game.
Marks the given position on the board with the current player's symbol.
Resets the game state to the initial state and broadcasts an update.
Starts a new Tic Tac Toe game agent.
Functions
child_spec(arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
crash_server()
@spec crash_server() :: no_return()
Crashes the Agent intentionally for testing purposes.
get_state()
@spec get_state() :: GameApp.Games.TicTacToe.GameLogic.t()
Retrieves the current state of the game.
initial_state()
@spec initial_state() :: GameApp.Games.TicTacToe.GameLogic.t()
Returns the initial state of the Tic Tac Toe game.
mark(position)
@spec mark(GameApp.Games.TicTacToe.GameLogic.position()) :: :ok | {:error, :invalid_position}
Marks the given position on the board with the current player's symbol.
Parameters
position
: The position to be marked (e.g.,:a1
,:b2
).
Returns
:ok
if the position was successfully marked.{:error, :invalid_position}
if the position is invalid or already marked.
Examples
iex> GameApp.Games.TicTacToe.mark(:a1)
:ok
iex> GameApp.Games.TicTacToe.mark(:a1)
{:error, :invalid_position}
reset()
@spec reset() :: :ok
Resets the game state to the initial state and broadcasts an update.
start_link(opts \\ [])
@spec start_link(Keyword.t()) :: {:ok, pid()} | {:error, {:already_started, pid()} | {:shutdown, term()} | term()}
Starts a new Tic Tac Toe game agent.
Options
opts
: Keyword list of options passed toAgent.start_link/2
.
Examples
iex> {:ok, pid} = GameApp.Games.TicTacToe.start_link(name: :tic_tac_toe)