tictactoe: github.com/shurcooL/tictactoe Index | Files | Directories

package tictactoe

import "github.com/shurcooL/tictactoe"

Package tictactoe defines the game of tic-tac-toe.

Index

Package Files

tictactoe.go

type Board Uses

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 Uses

func (b *Board) Apply(move Move, mark State) error

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.

func (Board) Condition Uses

func (b Board) Condition() Condition

Condition returns the condition of the board.

func (Board) String Uses

func (b Board) String() string

type Condition Uses

type Condition uint8

Condition of the board configuration.

const (
    NotEnd Condition = iota
    XWon
    OWon
    Tie
)

Conditions of the board configuration.

func (Condition) String Uses

func (c Condition) String() string

type Imager Uses

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 Uses

type Move int

Move is the board cell index where to place one's mark, a value in range [0, 9).

func (Move) Validate Uses

func (m Move) Validate() error

Validate reports if the move is valid. It may not be legal depending on the board configuration.

type Player Uses

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.

type State Uses

type State uint8

State of a board cell.

const (
    F   State = iota // Free cell.
    X                // Cell with an X mark.
    O                // Cell with an O mark.
)

States of a board cell.

func (State) String Uses

func (s State) String() string

Directories

PathSynopsis
cmd/tictactoetictactoe plays a game of tic-tac-toe with two players.
player/badPackage bad contains a bad tic-tac-toe player.
player/randomPackage random implements a random player of tic-tac-toe.

Package tictactoe imports 4 packages (graph) and is imported by 3 packages. Updated 2017-03-20. Refresh now. Tools for package owners.