Documentation ¶
Overview ¶
Package sgf reads and writes Smart Game Format (SGF) files. https://www.red-bean.com/sgf/index.html
Index ¶
- type BoardSize
- type Collection
- type Move
- type Properties
- func (n Properties) GetNumber(name string) (int, error)
- func (n Properties) GetNumberDefault(name string, defaultValue int) (int, error)
- func (n Properties) GetReal(name string) (float64, error)
- func (n Properties) GetRealDefault(name string, defaultValue float64) (float64, error)
- func (n Properties) GetSimpleText(name string) (string, error)
- func (n Properties) GetSimpleTextDefault(name string, defaultValue string) (string, error)
- type Tree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoardSize ¶
func (BoardSize) DecodeMove ¶
in SGF, "aa" is the top left corner
func (BoardSize) EncodeMove ¶
type Collection ¶
type Collection []*Tree
A Collection is a slice of game trees.
func ReadFile ¶
func ReadFile(fileName string) (Collection, error)
ReadFile reads a collection of games from the given file.
type Move ¶
type Move struct { X int8 // column, 0-based, from left to right Y int8 // row, 0-based, from bottom to top }
Move represents a move in a game of Go. The coordinates are 0-based, with (0,0) being the top left corner. If the move is a pass, X and Y are -1.
type Properties ¶
Properties of a game tree node are given as a map from property names to property values.
func (Properties) GetNumber ¶
func (n Properties) GetNumber(name string) (int, error)
GetNumber returns the value of the property with the given name as a number. If the property is missing, has more than one value, or the value is not an integer, an error is returned.
func (Properties) GetNumberDefault ¶
func (n Properties) GetNumberDefault(name string, defaultValue int) (int, error)
GetNumberDefault returns the value of the property with the given name as a number. If the property is missing, the defaultValue is returned. It the property has more than one value, or the value is not an integer, an error is returned.
func (Properties) GetReal ¶
func (n Properties) GetReal(name string) (float64, error)
GetReal returns the value of the property with the given name as a floating point number. If the property is missing, has more than one value, or the value is not a valid number, an error is returned.
func (Properties) GetRealDefault ¶
func (n Properties) GetRealDefault(name string, defaultValue float64) (float64, error)
GetRealDefault returns the value of the property with the given name as a floating point number. If the property is missing, the defaultValue is returned. It the property has more than one value, or the value is not a valid number, an error is returned.
func (Properties) GetSimpleText ¶
func (n Properties) GetSimpleText(name string) (string, error)
GetSimpleText returns the value of the property with the given name as a simple text. If the property is missing or has more than one value, an error is returned.
func (Properties) GetSimpleTextDefault ¶
func (n Properties) GetSimpleTextDefault(name string, defaultValue string) (string, error)
GetSimpleTextDefault returns the value of the property with the given name as a simple text. If the property is missing, the defaultValue is returned. If the property has more than one value, an error is returned.
type Tree ¶
type Tree struct { Properties Children []*Tree }
A Tree represents a node in a game tree.
func (*Tree) GetBoardSize ¶
func (*Tree) IsLinear ¶
IsLinear checks whether the game tree is linear, i.e. whether all nodes have at most one child.
func (*Tree) MainVariation ¶
func (t *Tree) MainVariation() []Properties
MainVariation returns the main variation of the game tree. This is the sequence of nodes starting at the root node and following the first child of each node.
func (*Tree) MainVariationMoves ¶
MainVariationMoves returns the main variation of the game tree, as a sequence of moves. The moves are played alternatingly by black and white, starting with black. Any trailing passes present in the SGF file are included.