tictactoe

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2020 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package tictactoe is a Tic-Tac-Toe game engine.

Index

Constants

View Source
const (
	//SIZE is the size of the board
	SIZE = 3

	//X represents player X
	X = 'x'

	//O represents player O
	O = 'o'
)

Variables

View Source
var (
	//ErrGameNotOver error
	ErrGameNotOver = errors.New("Game is not finished")

	//ErrInvalidMove error
	ErrInvalidMove = errors.New("Move is invalid")
)

Functions

This section is empty.

Types

type Game

type Game struct {
	// contains filtered or unexported fields
}

Game represents the current game state.

func NewGame

func NewGame() Game

NewGame returns a valid new game of tic-tac-toe.

func (Game) ApplyAction

func (g Game) ApplyAction(m Move) (Game, error)

ApplyAction takes a Move and applies the action to the current game state.

Returns the new game state and an error if any occurred.

func (Game) GetActions

func (g Game) GetActions() (moves []Move)

GetActions returns a list of moves that can be made by the current player.

func (Game) IsTerminal

func (g Game) IsTerminal() bool

IsTerminal returns whether the game is finished or not.

func (Game) Player

func (g Game) Player() byte

Player returns the ascii value of the player that is currently deciding a move.

Player returns 'o' if player o is making a move. Otherwise, Player return 'x'.

func (Game) String

func (g Game) String() string

func (Game) Winner

func (g Game) Winner() (byte, error)

Winner returns the winner's ascii value.

If the game resulted in a draw, it returns '_'.

Returns ErrGameNotOver if the game is not over.

type Move

type Move struct {
	// contains filtered or unexported fields
}

Move represents an action made by a given player.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL