围碁

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: 12 Imported by: 0

Documentation

Overview

package 围碁 implements Go (the board game) related code

围碁 is a bastardized word. The first character is read "wei" in Chinese. The second is read "qi" in Chinese. However, the charcter 碁 is no longer actively used in Chinese. It is however, actively used in Japanese. Specifically, it's read "go" in Japanese.

The main reason why this package is named with unicode characters instead of `package go` is because the standard library of the Go language have the prefix "go"

Index

Constants

View Source
const (
	BORDER = -1
	EMPTY  = 0
	BLACK  = 1 // Don't change
	WHITE  = 2 // these now
)
View Source
const (
	None  = game.None
	Black = game.Black
	White = game.White

	BlackP = game.Player(game.Black)
	WhiteP = game.Player(game.White)
)

Variables

This section is empty.

Functions

func IsValid

func IsValid(p game.Player) bool

IsValid checks that a player is indeed valid

func Opponent

func Opponent(p game.Player) game.Player

Opponent returns the colour of the opponent player

func StartGTP

func StartGTP(genmove func(colour int, board *GTPBoard) string, name string, version string)

Types

type AgogoBoard

type AgogoBoard struct {
	State game.State
}

type Board

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

Board represetns a board.

The board was originally implemented with a *tensor.Dense. However it turns out that if many iterations of the board were needed, we would quite quickly run out of memory because the *tensor.Dense data structure is quite huge.

Given we know the stride of the board, a decision was made to cull the fat from the data structure.

func (*Board) Apply

func (b *Board) Apply(m game.PlayerMove) (byte, error)

Apply returns the number of captures or an error, if a move were to be applied

func (*Board) Clone

func (b *Board) Clone() *Board

Clone clones the board

func (*Board) Eq

func (b *Board) Eq(other *Board) bool

Eq checks that both are equal

func (*Board) Format

func (b *Board) Format(s fmt.State, c rune)

Format implements fmt.Formatter

func (*Board) Hash

func (b *Board) Hash() int32

Hash returns the calculated hash of the board

func (*Board) Reset

func (b *Board) Reset()

Reset resets the board state

func (*Board) Score

func (b *Board) Score(player game.Player) float32

type GTPBoard

type GTPBoard struct {
	State       [][]int
	Ko          Point
	Size        int
	Komi        float64
	NextPlayer  int
	CapsByBlack int
	CapsByWhite int
}

func NewGTPBoard

func NewGTPBoard(size int, komi float64) *GTPBoard

func (*GTPBoard) AllLegalMoves

func (b *GTPBoard) AllLegalMoves(colour int) []Point

func (*GTPBoard) Clear

func (b *GTPBoard) Clear()

func (*GTPBoard) Copy

func (b *GTPBoard) Copy() *GTPBoard

func (*GTPBoard) Dump

func (b *GTPBoard) Dump()

func (*GTPBoard) GroupHasLiberties

func (b *GTPBoard) GroupHasLiberties(x, y int) bool

func (*GTPBoard) NewFromMove

func (b *GTPBoard) NewFromMove(colour, x, y int) (*GTPBoard, error)

func (*GTPBoard) NewFromPass

func (b *GTPBoard) NewFromPass(colour int) (*GTPBoard, error)

func (*GTPBoard) Pass

func (b *GTPBoard) Pass(colour int) error

func (*GTPBoard) PlayMove

func (b *GTPBoard) PlayMove(colour, x, y int) error

func (*GTPBoard) String

func (b *GTPBoard) String() string

func (*GTPBoard) StringFromPoint

func (b *GTPBoard) StringFromPoint(p Point) string

func (*GTPBoard) StringFromXY

func (b *GTPBoard) StringFromXY(x, y int) string

func (*GTPBoard) XYFromString

func (b *GTPBoard) XYFromString(s string) (int, int, error)

type Game

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

Game implements game.State and mcts.GameState

func New

func New(boardSize, handicap int, komi float64) *Game

func (*Game) ActionSpace

func (g *Game) ActionSpace() int

func (*Game) AdditionalScore

func (g *Game) AdditionalScore() float32

func (*Game) Apply

func (g *Game) Apply(m game.PlayerMove) game.State

func (*Game) Board

func (g *Game) Board() []game.Colour

func (*Game) BoardSize

func (g *Game) BoardSize() (int, int)

func (*Game) Check

func (g *Game) Check(m game.PlayerMove) bool

func (*Game) Clone

func (g *Game) Clone() game.State

func (*Game) Ended

func (g *Game) Ended() (ended bool, winner game.Player)

func (*Game) Eq

func (g *Game) Eq(other game.State) bool

func (*Game) Fwd

func (g *Game) Fwd()

func (*Game) Handicap

func (g *Game) Handicap() int

func (*Game) Hash

func (g *Game) Hash() game.Zobrist

func (*Game) Historical

func (g *Game) Historical(i int) []game.Colour

func (*Game) IsEye

func (g *Game) IsEye(m game.PlayerMove) bool

func (*Game) LastMove

func (g *Game) LastMove() game.PlayerMove

func (*Game) MoveNumber

func (g *Game) MoveNumber() int

func (*Game) Passes

func (g *Game) Passes() int

func (*Game) Reset

func (g *Game) Reset()

func (*Game) Score

func (g *Game) Score(p game.Player) float32

func (*Game) SetToMove

func (g *Game) SetToMove(p game.Player)

func (*Game) SuperKo

func (g *Game) SuperKo() bool

func (*Game) ToMove

func (g *Game) ToMove() game.Player

func (*Game) UndoLastMove

func (g *Game) UndoLastMove()

type Point

type Point struct {
	X int
	Y int
}

func AdjacentPoints

func AdjacentPoints(x, y int) []Point

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