agogo

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: MIT Imports: 21 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

agogo

A reimplementation of AlphaGo in Go (specifically AlphaZero)

TODO: Write proper docs. comment all the things

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeTwoPlayerBoard

func EncodeTwoPlayerBoard(a []game.Colour, prealloc []float32) []float32

EncodeTwoPlayerBoard encodes black as 1, white as -1 for each stone placed

func MakeIterator

func MakeIterator(board []float32, m, n int) (retVal [][]float32)

MakeIterator makes a generic iterator of a board

func ReturnIterator

func ReturnIterator(m, n int, it [][]float32)

func RotateBoard

func RotateBoard(board []float32, m, n int) ([]float32, error)

func WQEncoder

func WQEncoder(a game.State) []float32

WQEncoder encodes a Go board

Types

type AZ

type AZ struct {
	// state
	Arena
	Statistics
	// contains filtered or unexported fields
}

func New

func New(g game.State, conf Config) *AZ

func (*AZ) Learn

func (a *AZ) Learn(iters, episodes, nniters, arenaGames int) error

Learn learns for iters. It self-plays for episodes, and then trains a new NN from the self play example.

func (*AZ) Load

func (a *AZ) Load(filename string) error

func (*AZ) Save

func (a *AZ) Save(filename string) error

func (*AZ) SelfPlay

func (a *AZ) SelfPlay() []Example

SelfPlay plays an episode

type Agent

type Agent struct {
	NN     *dual.Dual
	MCTS   *mcts.MCTS
	Player game.Player
	Enc    GameEncoder

	// Statistics
	Wins float32
	Loss float32
	Draw float32
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Agent) Close

func (a *Agent) Close() error

func (*Agent) Infer

func (a *Agent) Infer(g game.State) (policy []float32, value float32)

Infer infers a bunch of moves based on the game state. This is mainly used to implement a Inferer such that the MCTS search can use it.

func (*Agent) NNOutput

func (a *Agent) NNOutput(g game.State) (policy []float32, value float32, err error)

NNOutput returns the output of the neural network

func (*Agent) Search

func (a *Agent) Search(g game.State) game.Single

Search searches the game state and returns a suggested coordinate.

func (*Agent) SwitchToInference

func (a *Agent) SwitchToInference(g game.State) (err error)

SwitchTOInference uses the inference mode neural network.

type Arena

type Arena struct {
	A, B *Agent
	// contains filtered or unexported fields
}

func MakeArena

func MakeArena(g game.State, a, b Dualer, conf mcts.Config, enc GameEncoder, aug Augmenter, name string) Arena

MakeArena makes an arena given a game.

func NewArena

func NewArena(g game.State, a, b Dualer, conf mcts.Config, enc GameEncoder, aug Augmenter, name string) *Arena

func (*Arena) Epoch

func (a *Arena) Epoch() int

func (*Arena) GameNumber

func (a *Arena) GameNumber() int

func (*Arena) Log

func (a *Arena) Log(w io.Writer)

func (*Arena) Name

func (a *Arena) Name() string

func (*Arena) Play

func (a *Arena) Play(record bool, enc OutputEncoder, aug Augmenter) (winner game.Player, examples []Example)

Play plays a game, and retrns a winner. If it is a draw, the returned colour is None.

func (*Arena) Score

func (a *Arena) Score(p game.Player) float64

func (*Arena) State

func (a *Arena) State() game.State

type Augmenter

type Augmenter func(a Example) []Example

Augmenter takes an example, and creates more examples from it.

type Config

type Config struct {
	Name            string
	NNConf          dual.Config
	MCTSConf        mcts.Config
	UpdateThreshold float64
	MaxExamples     int // maximum number of examples

	// extensions
	Encoder       GameEncoder
	OutputEncoder OutputEncoder
	Augmenter     Augmenter
}

type Dualer

type Dualer interface {
	Dual() *dual.Dual
}

Dualer is an interface for anything that allows getting out a *Dual.

Its sole purpose is to form a monoid-ish data structure for Agent.NN

type Example

type Example struct {
	Board  []float32
	Policy []float32
	Value  float32
}

Example is a representation of an example.

type ExecLogger

type ExecLogger interface {
	ExecLog() string
}

ExecLogger is anything that can return the execution log.

type GameEncoder

type GameEncoder func(a game.State) []float32

GameEncoder encodes a game state as a slice of floats

type Inferer

type Inferer interface {
	Infer(a []float32) (policy []float32, value float32, err error)
	io.Closer
}

Inferer is anything that can infer given an input.

type OutputEncoder

type OutputEncoder interface {
	Encode(ms game.MetaState) error
	Flush() error
}

OutputEncoder encodes the entire meta state as whatever.

An example OutputEncoder is the GifEncoder. Another example would be a logger.

type Statistics

type Statistics struct {
	Creation []string
	Wins     map[string][]float32
	Losses   map[string][]float32
	Draws    map[string][]float32
}

func (*Statistics) Dump

func (s *Statistics) Dump(filename string) error

Directories

Path Synopsis
cmd
tictactoe command
c4
mnk
wq
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
y or Y : Canonical URL
⌂ 换网址