-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.go
95 lines (80 loc) · 1.54 KB
/
seed.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
83
84
85
86
87
88
89
90
91
92
93
94
95
package seed
import (
"math/rand"
"time"
)
// Seed type
type Seed struct {
seed string
}
// Card seeds
const (
seedDenari = "DENARI"
seedSpade = "SPADE"
seedBastoni = "BASTONI"
seedCoppe = "COPPE"
)
// Random returns a random Seed
func Random() Seed {
rand.Seed(time.Now().UnixNano())
it := Iterable()
return it[rand.Intn(len(it))]
}
// Denari returns a Denari
func Denari() Seed {
return Seed{seedDenari}
}
// Spade returns a SeedSpade
func Spade() Seed {
return Seed{seedSpade}
}
// Bastoni returns a Basotni
func Bastoni() Seed {
return Seed{seedBastoni}
}
// Coppe returns a Coppe
func Coppe() Seed {
return Seed{seedCoppe}
}
// Iterable returns an iterable object of strings
func Iterable() []Seed {
return []Seed{
Denari(),
Spade(),
Bastoni(),
Coppe(),
}
}
// IsValid checks if seed is valid
func (s Seed) IsValid() bool {
return s.IsSpade() || s.IsDenari() || s.IsCoppe() || s.IsBastoni()
}
// IsSpade returns true if seed is SeedSpade
func (s Seed) IsSpade() bool {
return s.seed == seedSpade
}
// IsDenari returns true if seed is SeedDenari
func (s Seed) IsDenari() bool {
return s.seed == seedDenari
}
// IsBastoni returns true if seed is SeedBastoni
func (s Seed) IsBastoni() bool {
return s.seed == seedBastoni
}
// IsCoppe returns true if seed is SeedCoppe
func (s Seed) IsCoppe() bool {
return s.seed == seedCoppe
}
func (s Seed) String() string {
switch true {
case s.IsCoppe():
return "C"
case s.IsSpade():
return "S"
case s.IsDenari():
return "D"
case s.IsBastoni():
return "B"
}
return "ERR!"
}