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

Link to this function

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec crash_server() :: no_return()

Crashes the Agent intentionally for testing purposes.

@spec get_state() :: GameApp.Games.TicTacToe.GameLogic.t()

Retrieves the current state of the game.

Link to this function

initial_state()

@spec initial_state() :: GameApp.Games.TicTacToe.GameLogic.t()

Returns the initial state of the Tic Tac Toe game.

@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}
@spec reset() :: :ok

Resets the game state to the initial state and broadcasts an update.

Link to this function

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

Examples

iex> {:ok, pid} = GameApp.Games.TicTacToe.start_link(name: :tic_tac_toe)