import "github.com/shurcooL/tictactoe"
Package tictactoe defines the game of tic-tac-toe.
type Board struct { // Cells is a 3x3 matrix in row major order. // Cells[3*r + c] is the cell in the r'th row and c'th column. // Move m will affect Cells[m]. Cells [9]State }
Board for tic-tac-toe.
Apply a valid move to this board. Mark is either X or O. If it's not a legal move, the board is not modified and the error is returned.
Condition returns the condition of the board.
type CellClicker interface { // CellClick is called when cell with // specified index is clicked. CellClick(index int) }
CellClicker is an optional interface implemented by players that wish to be notified about cell clicks.
Condition of the board configuration.
Conditions of the board configuration.
type Imager interface { // Image returns the URL of the player's image. // Optimal size is 100 by 100 pixels (or higher for high DPI screens). Image() template.URL }
Imager is an optional interface implemented by players that have an image that represents them.
Move is the board cell index where to place one's mark, a value in range [0, 9).
Validate reports if the move is valid. It may not be legal depending on the board configuration.
type Player interface { // Name of player. Name() string // Play takes a tic-tac-toe board b and returns the next move // for this player. Its mark is either X or O. // ctx is expected to have a deadline set, and Play may take time // to "think" until deadline is reached before returning. Play(ctx context.Context, b Board, mark State) (Move, error) }
Player of tic-tac-toe.
State of a board cell.
States of a board cell.
Path | Synopsis |
---|---|
cmd/tictactoe | tictactoe plays a game of tic-tac-toe with two players. |
player/bad | Package bad contains a bad tic-tac-toe player. |
player/human | Package human contains a human-controlled tic-tac-toe player. |
player/random | Package random implements a random player of tic-tac-toe. |
Package tictactoe imports 4 packages (graph) and is imported by 4 packages. Updated 2018-02-17. Refresh now. Tools for package owners.