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.
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
board()
@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
.
game_status()
@type game_status() :: :ongoing | :win | :tie
Represents the current status of the game. Can be :ongoing
, :win
, or :tie
.
player()
@type player() :: :x | :o
Represents the player in the game. Can be either :x
or :o
.
position()
@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.
topic()
@type topic() :: String.t()
win()
@type win() :: [atom()] | nil
Represents a winning combination of positions, or nil
if there is no winner.
Functions
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
valid_positions()
@spec valid_positions() :: [position()]
Returns the valid positions of the Tic Tac Toe board.