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

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

crash_server(pid)

@spec crash_server(pid()) :: :ok

Crashes the server.

Parameters

  • pid: The process identifier of the GenServer.

Returns

  • :ok

Retrieves the current state of the game.

Parameters

  • pid: The process identifier of the GenServer.

Returns

  • The current game state.
Link to this function

initial_state(topic)

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.
Link to this function

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.

Terminates the game server gracefully.

Parameters

  • pid: The process identifier of the GenServer.

Returns

  • :ok
Link to this function

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.