GameApp.Games.TicTacToe.GenServer (game_app v0.1.0)
A GenServer module to handle Tic Tac Toe game logic and state management.
This module implements the GameApp.Games.TicTacToe.Behavior
to manage the game state,
handle player moves, and broadcast updates using Phoenix PubSub.
Summary
Functions
Returns a specification to start this module under a supervisor.
Crashes the server.
Retrieves the current state of the game.
Initializes the game state with a given topic.
Marks a position on the game board.
Terminates the game server gracefully.
Starts the GenServer with the given options.
Functions
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
crash_server(pid)
@spec crash_server(pid()) :: :ok
Crashes the server.
Parameters
- pid: The process identifier of the GenServer.
Returns
- :ok
get_state(pid)
Retrieves the current state of the game.
Parameters
- pid: The process identifier of the GenServer.
Returns
- The current game state.
initial_state(topic)
@spec initial_state(GameApp.Games.TicTacToe.GameLogic.topic()) :: GameApp.Games.TicTacToe.GameLogic.t()
Initializes the game state with a given topic.
Parameters
- topic: The PubSub topic for broadcasting updates.
Returns
- The initial game state as a
%GameLogic{}
struct.
mark(pid, position)
Marks a position on the game board.
Parameters
- pid: The process identifier of the GenServer.
- position: The position to mark (must be a valid position).
Returns
- :ok if the position is valid.
{:error, :invalid_position}
if the position is invalid.
reset(pid)
Terminates the game server gracefully.
Parameters
- pid: The process identifier of the GenServer.
Returns
- :ok
start_link(opts \\ [])
Starts the GenServer with the given options.
Options
- :topic (optional): The PubSub topic for broadcasting updates. Defaults to
@default_topic
.
Returns
{:ok, pid}
on success.