lib

package
v0.0.0-...-622d342 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFirstPlayer

func GetFirstPlayer() (string, error)

func GetMove

func GetMove(board BoardToPlay, reader io.Reader) int

Types

type Board

type Board struct {
	// Tic-Tac-Toe board struct.
	Grid       [3][3]string
	TotalMoves int
	NextTurn   string
}

func NewBoard

func NewBoard(symbol string) *Board

func (Board) Clone

func (b Board) Clone() Board

func (Board) GameOver

func (b Board) GameOver() bool

func (*Board) GetValidMoves

func (b *Board) GetValidMoves() []int

func (*Board) PlayMove

func (b *Board) PlayMove(index int, symbol string)

func (Board) Print

func (b Board) Print()
Example
board := NewBoard("X")
board.Print()
Output:

[- - -]
[- - -]
[- - -]

func (Board) WhoseTurn

func (b Board) WhoseTurn() string

func (Board) Winner

func (b Board) Winner(symbol string) bool

type BoardToPlay

type BoardToPlay interface {
	PlayMove(int, string)
	GetValidMoves() []int
	Winner(string) bool
	GameOver() bool
	WhoseTurn() string
	Print()
	Clone() Board
}

Interface for Player and ComputerPlayer to take to represent a Board

type ComputerPlayer

type ComputerPlayer struct {
	// Simple AI for tic-tac-toe. Uses the minimax algorithm to choose moves
	Symbol   string
	Board    BoardToPlay
	NextMove int
}

func NewComputer

func NewComputer(board BoardToPlay) *ComputerPlayer

func (*ComputerPlayer) ComputerMove

func (c *ComputerPlayer) ComputerMove()

type Player

type Player struct {
	// Struct for the player. Lets the player play a move and that is it.
	Symbol string
	Board  BoardToPlay
}

func NewPlayer

func NewPlayer(board BoardToPlay) *Player

func (*Player) PlayerMove

func (p *Player) PlayerMove(index int)

Jump to

Keyboard shortcuts

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