-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathopeningmove.go
39 lines (32 loc) · 873 Bytes
/
openingmove.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
package main
//OpeningMove is a node that represents a move
type OpeningMove struct {
Count uint32 `json:"size"`
San string `json:"title"`
Children []*OpeningMove `json:"children"`
}
//Find returns the child OpeningMove that matches the san
func (om *OpeningMove) Find(san string) *OpeningMove {
for _, m := range om.Children {
if m.San == san {
return m
}
}
return nil
}
//Prune recursively prunes OpeningMove trees depending on threshold count
func (om *OpeningMove) Prune(threshold int) {
var toRemove []int
for i, m := range om.Children {
if m.Count < uint32(threshold) {
toRemove = append(toRemove, i)
}
}
for n, i := range toRemove {
nx := i - n
om.Children, om.Children[len(om.Children)-1] = append(om.Children[:nx], om.Children[nx+1:]...), nil
}
for _, m := range om.Children {
m.Prune(threshold)
}
}