Skip to content

Commit ecb3405

Browse files
committed
Add auto approve goal option (for CI mode)
1 parent 6dfd6b8 commit ecb3405

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

config/ssl-game-controller.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ game:
3737
ball-placement-min-distance-to-defense-area: 0.7
3838
ball-placement-min-robot-distance: 0.05
3939
distance-to-ball-in-stop: 0.5
40+
auto-approve-goals: false
4041
normal:
4142
half-duration: 5m
4243
half-time-duration: 5m

internal/app/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type Game struct {
5858
BallPlacementTolerance float64 `yaml:"ball-placement-tolerance"`
5959
BallPlacementMinRobotDistance float64 `yaml:"ball-placement-min-robot-distance"`
6060
DistanceToBallInStop float64 `yaml:"distance-to-ball-in-stop"`
61+
AutoApproveGoals bool `yaml:"auto-approve-goals"`
6162
}
6263

6364
// Network holds configs for network communication
@@ -169,6 +170,7 @@ func DefaultControllerConfig() (c Controller) {
169170
c.Game.BallPlacementTolerance = 0.15
170171
c.Game.BallPlacementMinRobotDistance = 0.05
171172
c.Game.DistanceToBallInStop = 0.5
173+
c.Game.AutoApproveGoals = false
172174

173175
c.Game.Normal.HalfDuration = 5 * time.Minute
174176
c.Game.Normal.HalfTimeDuration = 5 * time.Minute

internal/app/config/testdata/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ game:
3737
ball-placement-min-distance-to-defense-area: 0.7
3838
ball-placement-min-robot-distance: 0.05
3939
distance-to-ball-in-stop: 0.5
40+
auto-approve-goals: false
4041
normal:
4142
half-duration: 5m
4243
half-time-duration: 5m

internal/app/statemachine/change_gameevent.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ func (s *StateMachine) processChangeAddGameEvent(newState *state.State, change *
7878
log.Printf("Halt the game, because team %v might have scored a goal", byTeam)
7979
// halt the game to let the human referee decide if this was a valid goal
8080
changes = append(changes, s.newCommandChange(state.NewCommandNeutral(state.Command_HALT)))
81+
if s.gameConfig.AutoApproveGoals {
82+
changes = append(changes, createGameEventChange(state.GameEvent_GOAL, *gameEvent))
83+
}
8184
}
8285

8386
// bot substitution
@@ -157,18 +160,24 @@ func (s *StateMachine) processChangeAddGameEvent(newState *state.State, change *
157160

158161
// multipleFoulsChange creates a multiple fouls event change
159162
func (s *StateMachine) multipleFoulsChange(byTeam state.Team) *Change {
160-
eventType := state.GameEvent_MULTIPLE_FOULS
163+
return createGameEventChange(state.GameEvent_MULTIPLE_FOULS, state.GameEvent{
164+
Event: &state.GameEvent_MultipleFouls_{
165+
MultipleFouls: &state.GameEvent_MultipleFouls{
166+
ByTeam: &byTeam,
167+
},
168+
},
169+
},
170+
)
171+
}
172+
173+
func createGameEventChange(eventType state.GameEvent_Type, event state.GameEvent) *Change {
174+
event.Type = &eventType
175+
event.Origin = []string{changeOriginStateMachine}
161176
return &Change{
177+
Origin: &changeOriginStateMachine,
162178
Change: &Change_AddGameEvent{
163179
AddGameEvent: &AddGameEvent{
164-
GameEvent: &state.GameEvent{
165-
Type: &eventType,
166-
Event: &state.GameEvent_MultipleFouls_{
167-
MultipleFouls: &state.GameEvent_MultipleFouls{
168-
ByTeam: &byTeam,
169-
},
170-
},
171-
},
180+
GameEvent: &event,
172181
},
173182
},
174183
}

internal/app/statemachine/statemachine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010
)
1111

12-
const changeOriginStateMachine = "StateMachine"
12+
var changeOriginStateMachine = "StateMachine"
1313

1414
// StateMachine describes the state machine that translates changes into new states
1515
type StateMachine struct {

0 commit comments

Comments
 (0)