oxo3d

package
v0.0.0-...-fb64ae1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2018 License: MIT Imports: 3 Imported by: 4

Documentation

Overview

Minimax player with Alpha-beta pruning for Oxo3d

Heuristic player for Oxo3d

Minimax player for Oxo3d

Player interface for Oxo3d

Random player for Oxo3d

Index

Constants

View Source
const (
	// We keep count of how many X and O there are on each line by encoding them like this
	// numberOfXs * 5 + numberOfOs
	// Since Xs and Os are both 0..4 the max value here is 24
	XS = 5
	OS = 1

	// players
	NOONE = 0
	ME    = 1
	YOU   = -1
	DRAW  = 2

	// A score larger than any possible score
	INF = 0x7FFFFFFF
)
View Source
const (
	// Names for costs
	NONE = 0  // Nothing
	O1   = 1  // 1 * O
	O2   = 2  // 2 * O
	O3   = 3  // 3 * O
	O4   = 4  // 4 * O
	X1   = 5  // 1 * X
	X2   = 6  // 2 * X
	X3   = 7  // 3 * X
	X4   = 8  // 4 * X
	O11  = 9  // An empty square with 1 * O and 1 * O
	O12  = 10 // An empty square with 1 * O and 2 * O
	O22  = 11 // An empty square with 2 * O and 2 * O
	X11  = 12 // An empty square with 1 * X and 1 * X
	X12  = 13 // An empty square with 1 * X and 2 * X
	X22  = 14 // An empty square with 2 * X and 2 * X
	JUNK = 15 // A line with both Os and Xs
)

Constants

Variables

View Source
var Players = map[string]NewPlayer{}

Registry of players

Functions

This section is empty.

Types

type NewPlayer

type NewPlayer func(*Oxo3d) Player

type Oxo3d

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

func NewOxo3d

func NewOxo3d(first bool) *Oxo3d

Create a new Oxo3d instance

func (*Oxo3d) Board

func (o *Oxo3d) Board(Go int) int

Board returns the state of the board at that position, either ME, YOU or NOONE

func (*Oxo3d) GameOver

func (o *Oxo3d) GameOver() bool

Test to see if someone won or it was a draw

func (*Oxo3d) IsMyGo

func (o *Oxo3d) IsMyGo() bool

Returns true if it is my go

func (*Oxo3d) Marked

func (o *Oxo3d) Marked(Go int) bool

Marked returns a flag as to whether the position should be higlighted. This will highlight the last move and any winning lines.

func (*Oxo3d) MyGo

func (o *Oxo3d) MyGo(Go int)

Do the computer move

func (*Oxo3d) Play

func (o *Oxo3d) Play(Go int, myGo bool)

Keep internal state up to date when a piece is played

func (*Oxo3d) String

func (o *Oxo3d) String() string

Turn the board into a string

func (*Oxo3d) UnPlay

func (o *Oxo3d) UnPlay()

Unplay the last move keeping internal state up to date

func (*Oxo3d) ValidMove

func (o *Oxo3d) ValidMove(Go int) bool

Returns true if the move is to an empty square Returns false if occupied or invalid

func (*Oxo3d) WhoWon

func (o *Oxo3d) WhoWon() int

Returns NOONE, ME, YOU or DRAW for who won

func (*Oxo3d) YourGo

func (o *Oxo3d) YourGo(Go int)

Do the opponents move

type Oxo3dAlphaBeta

type Oxo3dAlphaBeta struct {
	Oxo3dMinimax
}

func (*Oxo3dAlphaBeta) CalculateMyGo

func (p *Oxo3dAlphaBeta) CalculateMyGo() int

Do the computer move

type Oxo3dHeuristic

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

Oxo3d Heuristic player

func (*Oxo3dHeuristic) CalculateMyGo

func (p *Oxo3dHeuristic) CalculateMyGo() int

Calculate the computer move

func (*Oxo3dHeuristic) Play

func (p *Oxo3dHeuristic) Play(Go int, myGo bool)

Do a move

type Oxo3dMinimax

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

func (*Oxo3dMinimax) CalculateMyGo

func (p *Oxo3dMinimax) CalculateMyGo() int

Do the computer move

func (*Oxo3dMinimax) Play

func (p *Oxo3dMinimax) Play(Go int, myGo bool)

Do a move

type Oxo3dRandom

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

func (*Oxo3dRandom) CalculateMyGo

func (p *Oxo3dRandom) CalculateMyGo() int

Do the computer move

func (*Oxo3dRandom) Play

func (p *Oxo3dRandom) Play(Go int, myGo bool)

Do a move

type Player

type Player interface {
	CalculateMyGo() int
	Play(int, bool)
}

func NewOxo3dAlphaBeta

func NewOxo3dAlphaBeta(o *Oxo3d, level int) Player

Initialise the player

func NewOxo3dHeuristic

func NewOxo3dHeuristic(o *Oxo3d, level int) Player

Initialise the player

func NewOxo3dMinimax

func NewOxo3dMinimax(o *Oxo3d, level int) Player

Initialise the player

func NewOxo3dRandom

func NewOxo3dRandom(o *Oxo3d) Player

Initialise the player

Jump to

Keyboard shortcuts

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