Ultimate Tic-Tac-Toe v0.1.0 UltimateTtt.Game.OuterBoard View Source

This module represents the larger, outer tic-tac-toe grid containing 9 inner tic-tac-toe grids (which are in turn represented by UltimateTtt.Game.InnerBoard). Normally you will not need to interact with this module directly as most of its functionality is exposed through UltimateTtt.Game.

Note that this module does not track player turn, nor does it it implement the rules restricting play to the board associated with the last played space, and thus any move into any empty space is valid unless the board is won or tied.

Link to this section Summary

Types

t()

An opaque data structure representing the larger, outer tic-tac-toe grid.

Functions

Deserializes a serialized board back into an actual board.

Returns the UltimateTtt.Game.InnerBoard stored at the given index.

Returns a new, empty board.

Attempts to place the given tile on the given board at the given space. Returns {:ok, new_board} if successful and {:err, :invalid_move} otherwise. The move is specified as {board_idx, space_idx}.

Serializes a board to a string representation

Returns the status of the board. This can be :in_progress, :tie, or {:win, player} (where player is :x or :o).

Returns the UltimateTtt.Game.tile/0 at the given space.

Determines if the given move is valid for the board. The move is specified as {board_idx, space_idx}.

Returns a list of all spaces representing valid moves on the board. No moves are considered valid once the board is won.

Link to this section Types

An opaque data structure representing the larger, outer tic-tac-toe grid.

Link to this section Functions

Link to this function

deserialize(serialized)

View Source
deserialize(binary()) :: t()

Deserializes a serialized board back into an actual board.

Link to this function

inner_board_at(board, index)

View Source
inner_board_at(t(), number()) :: UltimateTtt.Game.InnerBoard.t()

Returns the UltimateTtt.Game.InnerBoard stored at the given index.

Returns a new, empty board.

Link to this function

place_tile(board, tile, space)

View Source
place_tile(t(), UltimateTtt.Game.player(), UltimateTtt.Game.space()) ::
  {:ok, t()} | {:err, :invalid_move}

Attempts to place the given tile on the given board at the given space. Returns {:ok, new_board} if successful and {:err, :invalid_move} otherwise. The move is specified as {board_idx, space_idx}.

Link to this function

serialize(board)

View Source
serialize(t()) :: binary()

Serializes a board to a string representation

Returns the status of the board. This can be :in_progress, :tie, or {:win, player} (where player is :x or :o).

Returns the UltimateTtt.Game.tile/0 at the given space.

Examples

iex> alias UltimateTtt.Game.OuterBoard
iex> board = OuterBoard.new()
iex> OuterBoard.tile_at(board, {0, 0})
:empty
iex> {:ok, board} = OuterBoard.place_tile(board, :x, {0, 0})
iex> OuterBoard.tile_at(board, {0, 0})
:x
Link to this function

valid_move?(board, space)

View Source
valid_move?(t(), UltimateTtt.Game.space()) :: boolean()

Determines if the given move is valid for the board. The move is specified as {board_idx, space_idx}.

Example

iex> alias UltimateTtt.Game.OuterBoard
iex> board = OuterBoard.new()
iex> OuterBoard.valid_move?(board, {0, 0})
true
iex> {:ok, board} = OuterBoard.place_tile(board, :x, {0, 0})
iex> OuterBoard.valid_move?(board, {0, 0})
false
Link to this function

valid_moves(board)

View Source
valid_moves(t()) :: [UltimateTtt.Game.space()]

Returns a list of all spaces representing valid moves on the board. No moves are considered valid once the board is won.