sgf

package module
v0.0.0-...-7d56f35 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package sgf reads and writes Smart Game Format (SGF) files. https://www.red-bean.com/sgf/index.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoardSize

type BoardSize struct {
	Width  int
	Height int
}

func (BoardSize) DecodeMove

func (sz BoardSize) DecodeMove(sgfMove string) Move

in SGF, "aa" is the top left corner

func (BoardSize) EncodeMove

func (sz BoardSize) EncodeMove(move Move) string

func (BoardSize) String

func (sz BoardSize) String() string

type Collection

type Collection []*Tree

A Collection is a slice of game trees.

func Read

func Read(r io.Reader) (Collection, error)

Read reads a collection of games from r.

func ReadFile

func ReadFile(fileName string) (Collection, error)

ReadFile reads a collection of games from the given file.

func (Collection) Write

func (c Collection) Write(w io.Writer) error

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

type Properties map[string][]string

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 (t *Tree) GetBoardSize() (BoardSize, error)

func (*Tree) IsLinear

func (t *Tree) IsLinear() bool

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

func (t *Tree) MainVariationMoves() ([]Move, error)

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.

Jump to

Keyboard shortcuts

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