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
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
Deserializes a serialized board back into an actual board.
inner_board_at(board, index)
View Sourceinner_board_at(t(), number()) :: UltimateTtt.Game.InnerBoard.t()
Returns the UltimateTtt.Game.InnerBoard
stored at the given index.
Returns a new, empty board.
place_tile(board, tile, space)
View Sourceplace_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}
.
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
).
tile_at(board, space)
View Sourcetile_at(t(), UltimateTtt.Game.space()) :: UltimateTtt.Game.tile()
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
valid_move?(board, space)
View Sourcevalid_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
Returns a list of all spaces representing valid moves on the board. No moves are considered valid once the board is won.