-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstate.go
60 lines (52 loc) · 1.07 KB
/
state.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
package main
import (
"log"
"math/rand"
"time"
)
type State struct {
Timer int
Holder string
LastUpdate time.Time
Participants []string
Aliases map[string]string
Scores map[string]int
Bets map[string]int
Reward int
}
func (s State) IsParticipant(id string) bool {
for _, p := range s.Participants {
if id == p {
return true
}
}
return false
}
func (s *State) Pass() {
var pool []string
for _, p := range s.Participants {
if p != s.Holder {
pool = append(pool, p)
}
}
var selection int
if len(pool) < 2 {
selection = 0
} else {
selection = rand.Intn(len(pool))
}
s.Holder = pool[selection]
s.LastUpdate = time.Now()
CLIENT_IRC.Say(CHANNEL, s.Aliases[s.Holder]+" has the potato! (!pass/!toss)")
log.Println("passed potato:", s.Holder)
}
func (s *State) Reset() {
s = &State{
Timer: rand.Intn(GAME_DURATION_MAX-GAME_DURATION_MIN+1) + GAME_DURATION_MIN,
Holder: "",
LastUpdate: time.Now(),
Participants: []string{},
Reward: REWARD_BASE,
Scores: map[string]int{},
}
}