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
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.
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}
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}
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
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
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]