-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
59 lines (51 loc) · 1.02 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package sgf
type Node struct {
Point Property
Properties []Property
Variations []*Node
Next *Node
}
func (node Node) variationString() string {
if len(node.Variations) == 0 {
return ""
}
str := ""
for _, nodevar := range node.Variations {
nodestr := ""
for nptr := nodevar; nptr != nil; nptr = nptr.Next {
nodestr += nptr.String()
}
str += "(" + nodestr + ")"
}
return str
}
func (node Node) propertiesString() string {
str := ""
for _, prop := range node.Properties {
str += prop.String()
}
return str
}
func (node Node) String() string {
return ";" +
node.Point.String() +
node.propertiesString() +
node.variationString()
}
func (node *Node) AddProperty(prop Property) {
switch prop.Name {
case "B", "W":
node.Point = prop
default:
node.Properties = append(node.Properties, prop)
}
}
func (node *Node) NewNode() *Node {
node.Next = new(Node)
return node.Next
}
func (n *Node) NewVariation() *Node {
node := new(Node)
n.Variations = append(n.Variations, node)
return node
}