Documentation
¶
Overview ¶
Package tictactoe defines the game of tic-tac-toe.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Board ¶
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.
func (*Board) Apply ¶
Apply a move to this board. Mark is either X or O. If the move is not valid or not legal, the board is not modified and an error is returned.
type CellClicker ¶
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.
type Imager ¶
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.
type Move ¶
type Move int
Move is the board cell index where to place one's mark, a value in range [0, 9).
A move is valid if it's in the range [0, 9). A move is legal if it can be applied to a given board configuration.
type Player ¶
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.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
tictactoe
command
tictactoe plays a game of tic-tac-toe with two players.
|
tictactoe plays a game of tic-tac-toe with two players. |
|
player
|
|
|
bad
Package bad contains a bad tic-tac-toe player.
|
Package bad contains a bad tic-tac-toe player. |
|
human
Package human contains a human-controlled tic-tac-toe player.
|
Package human contains a human-controlled tic-tac-toe player. |
|
perfect
Package perfect implements a perfect tic-tac-toe player.
|
Package perfect implements a perfect tic-tac-toe player. |
|
random
Package random implements a random player of tic-tac-toe.
|
Package random implements a random player of tic-tac-toe. |