-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiverse.go
82 lines (61 loc) · 1.38 KB
/
multiverse.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package multiverse
import (
"github.com/CasualSuperman/phonetics/metaphone"
)
func (m Multiverse) Loaded() bool {
return !m.Modified.IsZero()
}
// Initialize the phonetics map for a constructed Multiverse.
func (m Multiverse) initialize() {
markStandardSets(m.Sets)
markExtendedSets(m.Sets)
for i := range m.Cards {
m.Cards[i].scrub()
}
}
func markStandardSets(sets []Set) {
i := 0
for !sets[i].Type.isTournamentLegal() {
i++
}
mostRecentSet := sets[i]
coresInStandard := 1
mostRecentSetIsCoreSet := mostRecentSet.Type == SetTypes.Core
if mostRecentSetIsCoreSet {
coresInStandard++
}
i = 0
for coresInStandard > 0 || sets[i].Type != SetTypes.Core {
if sets[i].Type.isTournamentLegal() {
sets[i].standardLegal = true
if sets[i].Type == SetTypes.Core {
coresInStandard--
}
}
i++
}
}
func markExtendedSets(sets []Set) {
i := 0
for !sets[i].Type.isTournamentLegal() {
i++
}
mostRecentSet := sets[i]
mostRecentRelease := mostRecentSet.Released
releaseCutoff := mostRecentRelease.AddDate(-3, 0, 0)
i = 0
for sets[i].Released.After(releaseCutoff) {
if sets[i].Type.isTournamentLegal() {
sets[i].extendedLegal = true
}
i++
}
}
func (c *Card) scrub() {
c.ascii = preventUnicode(c.Name)
words := split(c.ascii)
c.metaphones = make([]string, len(words))
for j, str := range split(c.ascii) {
c.metaphones[j] = metaphone.Encode(str)
}
}