@@ -4,40 +4,47 @@ import (
4
4
"time"
5
5
)
6
6
7
+ // a team, one of Yellow or Blue
7
8
type Team string
8
9
9
- type RefBoxStage string
10
- type RefBoxGameState string
11
-
12
10
const (
13
11
TeamYellow Team = "Yellow"
14
12
TeamBlue Team = "Blue"
13
+ )
15
14
16
- StagePreGame RefBoxStage = "Pre-Game"
17
- StageFirstHalf RefBoxStage = "First Half"
18
- StageHalfTime RefBoxStage = "Half Time"
19
- StageSecondHalfPre RefBoxStage = "Pre-Second Half"
20
- StageSecondHalf RefBoxStage = "Second Half"
21
- StageOvertimeBreak RefBoxStage = "Overtime Break"
22
- StageOvertimeFirstHalfPre RefBoxStage = "Pre-Overtime First Half"
23
- StageOvertimeFirstHalf RefBoxStage = "Overtime First Half"
24
- StageOvertimeHalfTime RefBoxStage = "Overtime Half Time"
25
- StageOvertimeSecondHalfPre RefBoxStage = "Pre-Overtime Second Half"
26
- StageOvertimeSecondHalf RefBoxStage = "Overtime Second Half"
27
- StageShootoutBreak RefBoxStage = "Shootout Half Time"
28
- StageShootout RefBoxStage = "Shootout"
29
- StagePostGame RefBoxStage = "End of Game"
30
-
31
- GameStateHalted RefBoxGameState = "Halted"
32
- GameStateStopped RefBoxGameState = "Stopped"
33
- GameStateRunning RefBoxGameState = "Running"
34
- GameStatePreKickoff RefBoxGameState = "Prepare Kickoff"
35
- GameStatePrePenalty RefBoxGameState = "Prepare Penalty"
36
- GameStateTimeout RefBoxGameState = "Timeout"
37
- GameStateBallPlacement RefBoxGameState = "Ball Placement"
15
+ // return the other team
16
+ // if the team is not Yellow or Blue, return the same team
17
+ func (t Team ) Other () Team {
18
+ if t == TeamYellow {
19
+ return TeamBlue
20
+ } else if t == TeamBlue {
21
+ return TeamYellow
22
+ }
23
+ return t
24
+ }
25
+
26
+ // a stage of a match
27
+ type Stage string
28
+
29
+ const (
30
+ StagePreGame Stage = "Pre-Game"
31
+ StageFirstHalf Stage = "First Half"
32
+ StageHalfTime Stage = "Half Time"
33
+ StageSecondHalfPre Stage = "Pre-Second Half"
34
+ StageSecondHalf Stage = "Second Half"
35
+ StageOvertimeBreak Stage = "Overtime Break"
36
+ StageOvertimeFirstHalfPre Stage = "Pre-Overtime First Half"
37
+ StageOvertimeFirstHalf Stage = "Overtime First Half"
38
+ StageOvertimeHalfTime Stage = "Overtime Half Time"
39
+ StageOvertimeSecondHalfPre Stage = "Pre-Overtime Second Half"
40
+ StageOvertimeSecondHalf Stage = "Overtime Second Half"
41
+ StageShootoutBreak Stage = "Shootout Half Time"
42
+ StageShootout Stage = "Shootout"
43
+ StagePostGame Stage = "End of Game"
38
44
)
39
45
40
- var Stages = []RefBoxStage {
46
+ // all available stages, ordered
47
+ var Stages = []Stage {
41
48
StagePreGame ,
42
49
StageFirstHalf ,
43
50
StageHalfTime ,
@@ -54,7 +61,21 @@ var Stages = []RefBoxStage{
54
61
StagePostGame ,
55
62
}
56
63
57
- type RefBoxTeamState struct {
64
+ // a game state of a game
65
+ type GameState string
66
+
67
+ const (
68
+ GameStateHalted GameState = "Halted"
69
+ GameStateStopped GameState = "Stopped"
70
+ GameStateRunning GameState = "Running"
71
+ GameStatePreKickoff GameState = "Prepare Kickoff"
72
+ GameStatePrePenalty GameState = "Prepare Penalty"
73
+ GameStateTimeout GameState = "Timeout"
74
+ GameStateBallPlacement GameState = "Ball Placement"
75
+ )
76
+
77
+ // team information
78
+ type TeamInfo struct {
58
79
Name string `json:"name"`
59
80
Goals int `json:"goals"`
60
81
Goalie int `json:"goalie"`
@@ -66,57 +87,47 @@ type RefBoxTeamState struct {
66
87
OnPositiveHalf bool `json:"onPositiveHalf"`
67
88
}
68
89
69
- type RefBoxState struct {
70
- Stage RefBoxStage `json:"stage"`
71
- GameState RefBoxGameState `json:"gameState"`
72
- GameStateFor * Team `json:"gameStateForTeam"`
73
- GameTimeElapsed time.Duration `json:"gameTimeElapsed"`
74
- GameTimeLeft time.Duration `json:"gameTimeLeft"`
75
- MatchDuration time.Duration `json:"matchDuration"`
76
- TeamState map [Team ]* RefBoxTeamState `json:"teamState"`
90
+ // the state of the game
91
+ type State struct {
92
+ Stage Stage `json:"stage"`
93
+ GameState GameState `json:"gameState"`
94
+ GameStateFor * Team `json:"gameStateForTeam"`
95
+ StageTimeElapsed time.Duration `json:"gameTimeElapsed"`
96
+ StageTimeLeft time.Duration `json:"gameTimeLeft"`
97
+ MatchDuration time.Duration `json:"matchDuration"`
98
+ TeamState map [Team ]* TeamInfo `json:"teamState"`
77
99
}
78
100
79
- func NewRefBoxState (config Config ) (refBoxState * RefBoxState ) {
80
- refBoxState = new (RefBoxState )
101
+ // create a new state, initialized for the start of a new game
102
+ func NewRefBoxState (config Config ) (refBoxState * State ) {
103
+ refBoxState = new (State )
81
104
refBoxState .Stage = StagePreGame
82
105
refBoxState .GameState = GameStateHalted
83
106
84
107
// for some reason, the UI does not reset times correctly if duration is zero, so set it to 1ns
85
- refBoxState .GameTimeLeft = 1
86
- refBoxState .GameTimeElapsed = 1
108
+ refBoxState .StageTimeLeft = 1
109
+ refBoxState .StageTimeElapsed = 1
87
110
refBoxState .MatchDuration = 1
88
111
89
- refBoxState .TeamState = map [Team ]* RefBoxTeamState {}
90
- refBoxState .TeamState [TeamYellow ] = new (RefBoxTeamState )
91
- refBoxState .TeamState [TeamYellow ].Name = ""
92
- refBoxState .TeamState [TeamYellow ].Goals = 0
93
- refBoxState .TeamState [TeamYellow ].Goalie = 0
94
- refBoxState .TeamState [TeamYellow ].YellowCards = 0
95
- refBoxState .TeamState [TeamYellow ].YellowCardTimes = []time.Duration {}
96
- refBoxState .TeamState [TeamYellow ].RedCards = 0
97
- refBoxState .TeamState [TeamYellow ].TimeoutsLeft = config .Normal .Timeouts
98
- refBoxState .TeamState [TeamYellow ].TimeoutTimeLeft = config .Normal .TimeoutDuration
99
- refBoxState .TeamState [TeamYellow ].OnPositiveHalf = true
100
-
101
- refBoxState .TeamState [TeamBlue ] = new (RefBoxTeamState )
102
- refBoxState .TeamState [TeamBlue ].Name = ""
103
- refBoxState .TeamState [TeamBlue ].Goals = 0
104
- refBoxState .TeamState [TeamBlue ].Goalie = 0
105
- refBoxState .TeamState [TeamBlue ].YellowCards = 0
106
- refBoxState .TeamState [TeamBlue ].YellowCardTimes = []time.Duration {}
107
- refBoxState .TeamState [TeamBlue ].RedCards = 0
108
- refBoxState .TeamState [TeamBlue ].TimeoutsLeft = config .Normal .Timeouts
109
- refBoxState .TeamState [TeamBlue ].TimeoutTimeLeft = config .Normal .TimeoutDuration
110
- refBoxState .TeamState [TeamBlue ].OnPositiveHalf = false
112
+ refBoxState .TeamState = map [Team ]* TeamInfo {}
113
+ refBoxState .TeamState [TeamYellow ] = new (TeamInfo )
114
+ refBoxState .TeamState [TeamBlue ] = new (TeamInfo )
115
+ * refBoxState .TeamState [TeamYellow ] = NewTeamInfo (config )
116
+ * refBoxState .TeamState [TeamBlue ] = NewTeamInfo (config )
117
+ refBoxState .TeamState [TeamBlue ].OnPositiveHalf = ! refBoxState .TeamState [TeamYellow ].OnPositiveHalf
111
118
112
119
return
113
120
}
114
121
115
- func (t Team ) Other () Team {
116
- if t == TeamYellow {
117
- return TeamBlue
118
- } else if t == TeamBlue {
119
- return TeamYellow
120
- }
121
- return t
122
+ func NewTeamInfo (config Config ) (t TeamInfo ) {
123
+ t .Name = ""
124
+ t .Goals = 0
125
+ t .Goalie = 0
126
+ t .YellowCards = 0
127
+ t .YellowCardTimes = []time.Duration {}
128
+ t .RedCards = 0
129
+ t .TimeoutsLeft = config .Normal .Timeouts
130
+ t .TimeoutTimeLeft = config .Normal .TimeoutDuration
131
+ t .OnPositiveHalf = true
132
+ return
122
133
}
0 commit comments