Documentation
¶
Overview ¶
Package movetree contains logic for managing trees of moves in a game or problem. A movetree can be serialized to / deserialized from an SGF.
Index ¶
- Variables
- type GameInfo
- type MoveTree
- type Node
- func (n *Node) AddChild(nn *Node)
- func (n *Node) AnalysisData() interface{}
- func (n *Node) MoveNum() int
- func (n *Node) Next(variation int) *Node
- func (n *Node) SetAnalysisData(an interface{})
- func (n *Node) Traverse(fn func(node *Node))
- func (n *Node) TraverseMainBranch(fn func(node *Node))
- func (n *Node) VarNum() int
- type Path
Constants ¶
This section is empty.
Variables ¶
var ErrApplyTreepath = errors.New("error applying treepath")
var ErrParseTreepath = errors.New("error parsing treepath")
Functions ¶
This section is empty.
Types ¶
type GameInfo ¶
type GameInfo struct { // Size of the board, where 19 = 19x19. Between 1 and 25 inclusive. A value of // 0 should be taken to mean 'unspecified' and treated as 19x19. Size int // Komi are points added to the player with the white stones as compensation for playing second. // Komi must have a decimal value of .0 or .5 (ex: 6.5) Komi *float64 // Initial player turn. This is traditionally the player with the black stones Player color.Color }
GameInfo contains typed game properties that can exist only on the root.
type MoveTree ¶
type MoveTree struct {
Root *Node
}
MoveTree contains the game tree information for a go game.
type Node ¶
type Node struct { // Children of this position. Children []*Node // Parent of this node. Parent *Node // Move indicates a move in the game. A move with a color + no intersection is // used to indicate a pass. Move *move.Move // Placements are stones that are used for setup, but actual moves. For // example, handicap stones will be in in placements. Placements move.List // Comment is the comment for the current node. Comment string // GameInfo contains properties only found on the root. Should be nil on // non-root nodes. GameInfo *GameInfo // SGFProperties contain all the raw/unprocessed properties SGFProperties map[string][]string // contains filtered or unexported fields }
Node contains Properties, Children nodes, and Parent node.
func (*Node) AnalysisData ¶
func (n *Node) AnalysisData() interface{}
AnalysisData gets the attached analysis data, returning nil if the analysisData is empty.
func (*Node) Next ¶
Next gets the next node, given the variation number, returning nil if no node is available.
func (*Node) SetAnalysisData ¶
func (n *Node) SetAnalysisData(an interface{})
SetAnalysisData sets the analysis data.
func (*Node) TraverseMainBranch ¶
TraverseMainBranch Traverses the 0th variation nodes (Main Branch). This Traversal uses BFS.
type Path ¶
type Path []int
A Path is a list of variations that says how to travel through a tree of moves. And has two forms a list version and a string version. First, the list-version:
[0,1,0]
Means we will first take the 0th variation, then we will take the 1ist variation, and lastly we will take the 0th variation again. For convenience, the treepath can also be specified by a string, which is where the fun begins. At its simpliest,
[0,0,0] becomes 0.0.0
func ParsePath ¶
ParsePath parses a treepath from a string to an array of ints (Path).
There are a couple different string short-hands that make using treepaths a little easier
0-1x2 Take the 0th variation, then repeat taking the 1st varation twice
Paths say how to get from position n to position m. Thus the numbers are always variations, separated by '.' except in the case of A:B syntax, which means repeat A for B times.
A leading . is an optional. It can be useful to indicate the root node.
Some examples:
- becomes [] 0 becomes [0] -0 becomes [0] 1 becomes [1] 53 becomes [53] (the 53rd variation) 2-3 becomes [2,3] 0-0-0-0 becomes [0,0,0,0] 0x4 becomes [0,0,0,0] 1x4 becomes [1,1,1,1] 1-2x1-0-2x3 becomes [1,2,0,2,2,2]
func (Path) Apply ¶
Apply applies a treepath to a node, moving down a tree of moves. This takes the variation listed in the treepath until either:
1. There are no more variation numbers in the treepath. 2. There is not a child with the given variation number.
func (Path) ApplyToBoard ¶
ApplyToBoard applies a treepath to a Go-Board, returning the captured stones, or an error if the application was unsuccessful.
A board copy, and the relevant captures are returned
func (Path) CompactString ¶
CompactString returns the treepath as a CompactString (short-hand). examples:
[] becomes "-" [1] becomes "-1" [0,0,0,0] becomes "-0x4" [1,1,1,1] becomes "-1x4" [1,2,0,0,2,2,2] becomes "-1-2-0x2-2x3"