GameApp.Games.TicTacToe.GameLogic (game_app v0.1.0)

A module to handle the Tic Tac Toe game logic.

Summary

Types

Represents the game board. It is a map where the keys are positions and the values are either :x, :o, or nil.

Represents the current status of the game. Can be :ongoing, :win, or :tie.

Represents the player in the game. Can be either :x or :o.

Represents a valid position on the game board.

t()

Represents the state of the game. It includes

Represents a winning combination of positions, or nil if there is no winner.

Functions

takes state and new_board and returns the next player, win, and game status

Returns the valid positions of the Tic Tac Toe board.

Types

@type board() :: %{optional(atom()) => :x | :o | nil}

Represents the game board. It is a map where the keys are positions and the values are either :x, :o, or nil.

Link to this type

game_status()

@type game_status() :: :ongoing | :win | :tie

Represents the current status of the game. Can be :ongoing, :win, or :tie.

@type player() :: :x | :o

Represents the player in the game. Can be either :x or :o.

@type position() :: :a1 | :a2 | :a3 | :b1 | :b2 | :b3 | :c1 | :c2 | :c3

Represents a valid position on the game board.

@type t() :: %GameApp.Games.TicTacToe.GameLogic{
  board: board(),
  current_player: player(),
  game_status: game_status(),
  topic: topic(),
  win: win()
}

Represents the state of the game. It includes:

  • board: The current state of the game board.
  • current_player: The player whose turn it is.
  • win: The winning combination of positions, if any.
  • game_status: The current status of the game.
@type topic() :: String.t()
@type win() :: [atom()] | nil

Represents a winning combination of positions, or nil if there is no winner.

Functions

Link to this function

update_game(state, new_board)

@spec update_game(t(), board()) :: {player(), win(), game_status()}

takes state and new_board and returns the next player, win, and game status

Link to this function

valid_positions()

@spec valid_positions() :: [position()]

Returns the valid positions of the Tic Tac Toe board.