game

package
Version: v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeIterator

func MakeIterator(board []Colour, m, n int32) (retVal [][]Colour)

MakeIterator makes a generic iterator of a board of colours

func ReturnIterator

func ReturnIterator(m, n int32, it [][]Colour)

Types

type Colour

type Colour int32
const (
	None Colour = iota
	Black
	White
)

func (Colour) Format

func (cl Colour) Format(s fmt.State, c rune)

type Coord

type Coord struct {
	X, Y int16
}

Coord represents a (row, col) coordinate. Given we're unlikely to actually have a board size of 255x255 or greater, a pair of bytes is sufficient to represent the coordinates

The Coord uses a standard computer cartesian coordinates

- (0, 0) represents the top left
- (18, 18) represents the bottom right of a 19x19 board
- (255, 255) represents a "pass" move
- (254, 254) represents a "resign" move

func (Coord) Add

func (c Coord) Add(other Coord) struct{ X, Y int16 }

func (Coord) Eq

func (c Coord) Eq(other Coord) bool

func (Coord) IsPass

func (c Coord) IsPass() bool

IsPass returns true when the coordinate represents a "pass" move

func (Coord) IsResignation

func (c Coord) IsResignation() bool

IsResignation returns true when the coordinate represents a "resignation" move

type CoordConverter

type CoordConverter interface {
	Ltoi(Coord) Single
	Itol(Single) Coord
}

type Coordinate

type Coordinate interface {
	IsResignation() bool
	IsPass() bool
}

Coordinate is a representation of coordinates. This is typically a move

type GifEncoder

type GifEncoder struct {
	H, W int
	font.Drawer

	io.Writer
	// contains filtered or unexported fields
}

func NewGifEncoder

func NewGifEncoder(h, w int) *GifEncoder

func (*GifEncoder) Encode

func (enc *GifEncoder) Encode(ms MetaState) error

func (*GifEncoder) Flush

func (enc *GifEncoder) Flush() error

type KomiSetter

type KomiSetter interface {
	State
	SetKomi(komi float64) error
}

KomiSetter is any State that can set a Komi score.

The komi score may be acquired from the State via AdditionalScore()

type MetaState

type MetaState interface {
	Name() string // name of the game
	Epoch() int
	GameNumber() int
	Score(a Player) float64
	State() State
}

type Player

type Player Colour

Player represents a player. It's also a colour.

func (Player) Format

func (p Player) Format(s fmt.State, c rune)

type PlayerMove

type PlayerMove struct {
	Player
	Single
}

PlayerMove is a tuple indicating the player and the move to be made.

For now, the move is a Single. The original implementation took a Coordinate

func (PlayerMove) Eq

func (p PlayerMove) Eq(other PlayerMove) bool

Eq returns true if both are equal

func (PlayerMove) Format

func (p PlayerMove) Format(s fmt.State, c rune)

type Single

type Single int32

Single represents a coordinate as a single 8-bit number, utilized in a rowmajor fashion.

- 0 represents the top left
- 18 represents the top right
- 19 represents (1, 0)
- -1 represents the "pass" move
- -2 represents the "resignation" move

func (Single) IsPass

func (c Single) IsPass() bool

IsPass returns true when the coordinate represents a "pass" move

func (Single) IsResignation

func (c Single) IsResignation() bool

IsResignation returns true when the coordinate represents a "resignation" move

type State

type State interface {
	// These methods represent the game state
	BoardSize() (int, int) // returns the board size
	Board() []Colour       // returns the board state
	ActionSpace() int      // returns the number of permissible actions
	Hash() Zobrist         // returns the hash of the board
	ToMove() Player        // returns the next player to move (terminology is a bit confusing - this means the current player)
	Passes() int           // returns number of passes that have been made
	MoveNumber() int       // returns count of moves so far that led to this point.
	LastMove() PlayerMove  // returns the last move that was made
	Handicap() int         // returns a handicap (i.e. allow N moves)

	// Meta-game stuff
	Score(p Player) float32             // score of the given player
	AdditionalScore() float32           // additional tie breaking scores (like komi etc)
	Ended() (ended bool, winner Player) // has the game ended? if yes, then who's the winner?

	// interactions
	SetToMove(Player)         // set the next player to move
	Check(m PlayerMove) bool  // check if the placement is legal
	Apply(m PlayerMove) State // should return a GameState. The required side effect is the NextToMove has to change.
	Reset()                   // reset state

	// For MCTS
	Historical(i int) []Colour // returns the board state from history
	UndoLastMove()
	Fwd()

	// generics
	Eq(other State) bool
	Clone() State
}

State is any game that implements these and are able to report back

type Zobrist

type Zobrist uint32

Zobrist is a type representing a "zobrist" hash. The word "Zobrist" is put in quotes because only Go and chess uses zobrist hashing. Other games have different hashes of the boards (because only Go and Chess have subtractive boards)

Directories

Path Synopsis
package 围碁 implements Go (the board game) related code 围碁 is a bastardized word.
package 围碁 implements Go (the board game) related code 围碁 is a bastardized word.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL