Skip to content

Commit 5da8992

Browse files
committed
[feature] Report the remaining lack-of-progress time in referee msg
1 parent 715893d commit 5da8992

File tree

13 files changed

+259
-104
lines changed

13 files changed

+259
-104
lines changed

config/ssl-game-controller.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ game:
1616
multiple-placement-failures: 5
1717
auto-ref-proposal-timeout: 5s
1818
default-division: DivA
19+
lack-of-progress-free-kick-timeout:
20+
DivA: 5s
21+
DivB: 10s
22+
lack-of-progress-timeout: 10s
1923
normal:
2024
half-duration: 5m
2125
half-time-duration: 5m

internal/app/config/config.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ type Geometry struct {
3030

3131
// Game holds configs that are valid for the whole game
3232
type Game struct {
33-
YellowCardDuration time.Duration `yaml:"yellow-card-duration"`
34-
DefaultDivision Division `yaml:"default-division"`
35-
Normal Special `yaml:"normal"`
36-
Overtime Special `yaml:"overtime"`
37-
TeamChoiceTimeout time.Duration `yaml:"team-choice-timeout"`
38-
DefaultGeometry map[Division]*Geometry `yaml:"default-geometry"`
39-
MultipleCardStep int `yaml:"multiple-card-step"`
40-
MultipleFoulStep int `yaml:"multiple-foul-step"`
41-
MultiplePlacementFailures int `yaml:"multiple-placement-failures"`
42-
MaxBots map[Division]int `yaml:"max-bots"`
43-
AutoRefProposalTimeout time.Duration `yaml:"auto-ref-proposal-timeout"`
33+
YellowCardDuration time.Duration `yaml:"yellow-card-duration"`
34+
DefaultDivision Division `yaml:"default-division"`
35+
Normal Special `yaml:"normal"`
36+
Overtime Special `yaml:"overtime"`
37+
TeamChoiceTimeout time.Duration `yaml:"team-choice-timeout"`
38+
DefaultGeometry map[Division]*Geometry `yaml:"default-geometry"`
39+
MultipleCardStep int `yaml:"multiple-card-step"`
40+
MultipleFoulStep int `yaml:"multiple-foul-step"`
41+
MultiplePlacementFailures int `yaml:"multiple-placement-failures"`
42+
MaxBots map[Division]int `yaml:"max-bots"`
43+
AutoRefProposalTimeout time.Duration `yaml:"auto-ref-proposal-timeout"`
44+
LackOfProgressFreeKickTimeout map[Division]time.Duration `yaml:"lack-of-progress-free-kick-timeout"`
45+
LackOfProgressTimeout time.Duration `yaml:"lack-of-progress-timeout"`
4446
}
4547

4648
// Network holds configs for network communication
@@ -108,6 +110,8 @@ func DefaultControllerConfig() (c Controller) {
108110
c.Game.MultipleFoulStep = 3
109111
c.Game.MultiplePlacementFailures = 5
110112
c.Game.AutoRefProposalTimeout = 5 * time.Second
113+
c.Game.LackOfProgressTimeout = time.Second * 10
114+
c.Game.LackOfProgressFreeKickTimeout = map[Division]time.Duration{DivA: time.Second * 5, DivB: time.Second * 10}
111115

112116
c.Game.Normal.HalfDuration = 5 * time.Minute
113117
c.Game.Normal.HalfTimeDuration = 5 * time.Minute
@@ -149,9 +153,7 @@ func DefaultControllerConfig() (c Controller) {
149153
c.Game.DefaultGeometry[DivB].PlacementOffsetTouchLine = 0.2
150154
c.Game.DefaultGeometry[DivB].PlacementOffsetDefenseArea = 1.0
151155

152-
c.Game.MaxBots = map[Division]int{}
153-
c.Game.MaxBots[DivA] = 8
154-
c.Game.MaxBots[DivB] = 6
156+
c.Game.MaxBots = map[Division]int{DivA: 8, DivB: 6}
155157

156158
c.TimeFromVision = false
157159

internal/app/controller/engine.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ func (e *Engine) Tick(delta time.Duration) {
6363
if e.State.MatchTimeStart.After(time.Unix(0, 0)) {
6464
e.State.MatchDuration = e.TimeProvider().Sub(e.State.MatchTimeStart)
6565
}
66+
if e.State.LackOfProgressDeadline.After(time.Unix(0, 0)) {
67+
e.State.LackOfProgressTimeRemaining = e.RemainingLackOfProgressTime()
68+
}
69+
}
70+
71+
func (e *Engine) RemainingLackOfProgressTime() time.Duration {
72+
return e.State.LackOfProgressDeadline.Sub(e.TimeProvider())
6673
}
6774

6875
func (e *Engine) updateTimes(delta time.Duration) {
@@ -116,6 +123,14 @@ func (e *Engine) SendCommand(command RefCommand, forTeam Team) {
116123
e.State.PlacementPos = nil
117124
e.State.NextCommand = CommandUnknown
118125
e.State.NextCommandFor = TeamUnknown
126+
127+
if command != CommandKickoff && command != CommandPenalty {
128+
e.State.LackOfProgressTimeRemaining = e.config.LackOfProgressTimeout
129+
if command == CommandIndirect || command == CommandDirect {
130+
e.State.LackOfProgressTimeRemaining = e.config.LackOfProgressFreeKickTimeout[e.State.Division]
131+
}
132+
e.State.LackOfProgressDeadline = e.TimeProvider().Add(e.State.LackOfProgressTimeRemaining)
133+
}
119134
}
120135
}
121136

internal/app/controller/publisher.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func initRefereeMessage(m *refproto.Referee) {
7575
initTeamInfo(m.Blue)
7676
m.BlueTeamOnPositiveHalf = new(bool)
7777
m.NextCommand = new(refproto.Referee_Command)
78+
m.LackOfProgressTimeRemaining = new(int32)
7879
}
7980

8081
func initTeamInfo(t *refproto.Referee_TeamInfo) {
@@ -130,6 +131,7 @@ func (p *RefMessage) setState(state *State) (republish bool) {
130131
*p.referee.StageTimeLeft = int32(state.StageTimeLeft.Nanoseconds() / 1000)
131132
*p.referee.BlueTeamOnPositiveHalf = state.TeamState[TeamBlue].OnPositiveHalf
132133
*p.referee.NextCommand = mapCommand(state.NextCommand, state.NextCommandFor)
134+
*p.referee.LackOfProgressTimeRemaining = int32(state.LackOfProgressTimeRemaining.Nanoseconds() / 1000)
133135

134136
updateTeam(p.referee.Yellow, state.TeamState[TeamYellow])
135137
updateTeam(p.referee.Blue, state.TeamState[TeamBlue])

internal/app/controller/state.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -270,23 +270,25 @@ type GameEventProposal struct {
270270

271271
// State of the game
272272
type State struct {
273-
Stage Stage `json:"stage"`
274-
Command RefCommand `json:"command"`
275-
CommandFor Team `json:"commandForTeam"`
276-
GameEvents []*GameEvent `json:"gameEvents"`
277-
StageTimeElapsed time.Duration `json:"stageTimeElapsed"`
278-
StageTimeLeft time.Duration `json:"stageTimeLeft"`
279-
MatchTimeStart time.Time `json:"matchTimeStart"`
280-
MatchDuration time.Duration `json:"matchDuration"`
281-
TeamState map[Team]*TeamInfo `json:"teamState"`
282-
Division config.Division `json:"division"`
283-
PlacementPos *Location `json:"placementPos"`
284-
AutoContinue bool `json:"autoContinue"`
285-
NextCommand RefCommand `json:"nextCommand"`
286-
NextCommandFor Team `json:"nextCommandFor"`
287-
AutoRefsConnected []string `json:"autoRefsConnected"`
288-
GameEventBehavior map[GameEventType]GameEventBehavior `json:"gameEventBehavior"`
289-
GameEventProposals []*GameEventProposal `json:"gameEventProposals"`
273+
Stage Stage `json:"stage"`
274+
Command RefCommand `json:"command"`
275+
CommandFor Team `json:"commandForTeam"`
276+
GameEvents []*GameEvent `json:"gameEvents"`
277+
StageTimeElapsed time.Duration `json:"stageTimeElapsed"`
278+
StageTimeLeft time.Duration `json:"stageTimeLeft"`
279+
MatchTimeStart time.Time `json:"matchTimeStart"`
280+
MatchDuration time.Duration `json:"matchDuration"` // MatchDuration contains the updated match duration based on MatchTimeStart for the UI
281+
TeamState map[Team]*TeamInfo `json:"teamState"`
282+
Division config.Division `json:"division"`
283+
PlacementPos *Location `json:"placementPos"`
284+
AutoContinue bool `json:"autoContinue"`
285+
NextCommand RefCommand `json:"nextCommand"`
286+
NextCommandFor Team `json:"nextCommandFor"`
287+
AutoRefsConnected []string `json:"autoRefsConnected"`
288+
GameEventBehavior map[GameEventType]GameEventBehavior `json:"gameEventBehavior"`
289+
GameEventProposals []*GameEventProposal `json:"gameEventProposals"`
290+
LackOfProgressDeadline time.Time `json:"lackOfProgressDeadline"`
291+
LackOfProgressTimeRemaining time.Duration `json:"lackOfProgressTimeRemaining"` // LackOfProgressTimeRemaining contains the updated remaining lack of progress time for the UI
290292
}
291293

292294
// NewState creates a new state, initialized for the start of a new game
@@ -300,6 +302,7 @@ func NewState() (s *State) {
300302
s.StageTimeElapsed = 0
301303
s.MatchDuration = 0
302304
s.MatchTimeStart = time.Unix(0, 0)
305+
s.LackOfProgressDeadline = time.Unix(0, 0)
303306

304307
s.TeamState = map[Team]*TeamInfo{}
305308
s.TeamState[TeamYellow] = new(TeamInfo)

internal/app/controller/testdata/transition_ballplacement.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"stage": "First Half",
55
"command": "stop",
66
"commandForTeam": null,
7+
"division": "DivA",
78
"gameEvent": {
89
"type": "",
910
"forTeam": "",
@@ -13,6 +14,8 @@
1314
"stageTimeLeft": 300000000000,
1415
"matchDuration": 0,
1516
"matchTimeStart": "2006-01-02T15:04:05Z",
17+
"lackOfProgressTimeRemaining": 0,
18+
"lackOfProgressDeadline": "2006-01-02T15:04:05Z",
1619
"teamState": {
1720
"Blue": {
1821
"name": "",
@@ -50,6 +53,7 @@
5053
"stage": "First Half",
5154
"command": "ballPlacement",
5255
"commandForTeam": "Yellow",
56+
"division": "DivA",
5357
"gameEvent": {
5458
"type": "",
5559
"forTeam": "",
@@ -59,6 +63,8 @@
5963
"stageTimeLeft": 300000000000,
6064
"matchDuration": 0,
6165
"matchTimeStart": "2006-01-02T15:04:05Z",
66+
"lackOfProgressTimeRemaining": 0,
67+
"lackOfProgressDeadline": "2006-01-02T15:04:05Z",
6268
"teamState": {
6369
"Blue": {
6470
"name": "",
@@ -69,6 +75,7 @@
6975
"redCards": 0,
7076
"timeoutsLeft": 4,
7177
"timeoutTimeLeft": 300000000000,
78+
"maxAllowedBots": 8,
7279
"onPositiveHalf": false
7380
},
7481
"Yellow": {
@@ -80,6 +87,7 @@
8087
"redCards": 0,
8188
"timeoutsLeft": 4,
8289
"timeoutTimeLeft": 300000000000,
90+
"maxAllowedBots": 8,
8391
"onPositiveHalf": true
8492
}
8593
}
@@ -95,6 +103,7 @@
95103
"stage": "First Half",
96104
"command": "stop",
97105
"commandForTeam": null,
106+
"division": "DivA",
98107
"gameEvent": {
99108
"type": "",
100109
"forTeam": "",
@@ -104,6 +113,8 @@
104113
"stageTimeLeft": 300000000000,
105114
"matchDuration": 0,
106115
"matchTimeStart": "2006-01-02T15:04:05Z",
116+
"lackOfProgressTimeRemaining": 0,
117+
"lackOfProgressDeadline": "2006-01-02T15:04:05Z",
107118
"teamState": {
108119
"Blue": {
109120
"name": "",
@@ -114,6 +125,7 @@
114125
"redCards": 0,
115126
"timeoutsLeft": 4,
116127
"timeoutTimeLeft": 300000000000,
128+
"maxAllowedBots": 8,
117129
"onPositiveHalf": false
118130
},
119131
"Yellow": {
@@ -125,6 +137,7 @@
125137
"redCards": 0,
126138
"timeoutsLeft": 4,
127139
"timeoutTimeLeft": 300000000000,
140+
"maxAllowedBots": 8,
128141
"onPositiveHalf": true
129142
}
130143
}

0 commit comments

Comments
 (0)