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

This module represents one of the nine inner tic-tac-toe boards in a game of Ultimate Tic-Tac-Toe. Normally you will not need to interact with this module directly as most of its functionality is exposed through UltimateTtt.Game.OuterBoard.

Note that this module does not track player turn, and thus any move into any empty space is valid unless the board is won or tied.

Link to this section Summary

Functions

Deserializes a serialized board back into an actual board.

Returns a new, empty board.

Attempts to place the given tile on the board at the given space.

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 tile occupying the given space.

Returns a boolean specifying whether or not a given move is valid. space must be a number between 0 and 8, inclusive.

Returns a list of numbers that represent all valid moves for the board. No moves are considered valid once the board is won.

Link to this section Types

Link to this section Functions

Link to this function

deserialize(str)

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

Deserializes a serialized board back into an actual board.

Examples

iex> alias UltimateTtt.Game.InnerBoard
iex> InnerBoard.deserialize("x.......o")
#InnerBoard<"x.......o">

Returns a new, empty board.

Link to this function

place_tile(board, tile, space)

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

Attempts to place the given tile on the board at the given space.

Examples

iex> alias UltimateTtt.Game.InnerBoard
iex> board = InnerBoard.new()
iex> {:ok, board} = InnerBoard.place_tile(board, 0, :x)
iex> InnerBoard.place_tile(:board, 0, :o)
{:error, :invalid_move}
Link to this function

serialize(board)

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

Serializes a board to a string representation.

Examples

iex> alias UltimateTtt.Game.InnerBoard
iex> board = InnerBoard.new()
iex> {:ok, board} = InnerBoard.place_tile(board, :x, 0)
iex> {:ok, board} = InnerBoard.place_tile(board, :o, 8)
iex> InnerBoard.serialize(board)
"x.......o"

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

Examples

iex> alias UltimateTtt.Game.InnerBoard
iex> board = InnerBoard.new
iex> InnerBoard.status(board)
:in_progress

iex> alias UltimateTtt.Game.InnerBoard
iex> board = InnerBoard.deserialize("x...x...x")
iex> InnerBoard.status(board)
{:win, :x}
Link to this function

tile_at(board, space)

View Source
tile_at(t(), space()) :: tile()

Returns the tile occupying the given space.

Examples

iex> alias UltimateTtt.Game.InnerBoard
iex> board = InnerBoard.deserialize("xo.......")
iex> InnerBoard.tile_at(board, 1)
:o
iex> InnerBoard.tile_at(board, 2)
:empty
Link to this function

valid_move?(board, space)

View Source
valid_move?(t(), space()) :: boolean()

Returns a boolean specifying whether or not a given move is valid. space must be a number between 0 and 8, inclusive.

Examples

iex> alias UltimateTtt.Game.InnerBoard
iex> board = InnerBoard.new()
iex> InnerBoard.valid_move?(board, 0)
true
iex> InnerBoard.valid_move?(board, 9)
false

iex> alias UltimateTtt.Game.InnerBoard
iex> board = InnerBoard.deserialize(".x.ox...o")
iex> InnerBoard.valid_move?(board, 1)
false
Link to this function

valid_moves(board)

View Source
valid_moves(t()) :: [space()]

Returns a list of numbers that represent all valid moves for the board. No moves are considered valid once the board is won.

Examples

iex> alias UltimateTtt.Game.InnerBoard
iex> InnerBoard.valid_moves(InnerBoard.new)
[0, 1, 2, 3, 4, 5, 6, 7, 8]

iex> alias UltimateTtt.Game.InnerBoard
iex> ".x.ox...o"
...> |> InnerBoard.deserialize()
...> |> InnerBoard.valid_moves()
[0, 2, 5, 6, 7]