Skip to content

Commit 94eba6d

Browse files
committed
[feature] Move steps/boundaries of multiple* events to config
1 parent 2deeea5 commit 94eba6d

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

config/ssl-game-controller.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ server:
99
trusted-keys-dir: config/trusted_keys/team
1010
game:
1111
yellow-card-duration: 2m
12+
multiple-card-step: 3
13+
multiple-foul-step: 3
14+
multiple-placement-failures: 5
1215
default-division: DivA
1316
normal:
1417
half-duration: 5m

internal/app/controller/config.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ type ConfigGeometry struct {
2929

3030
// ConfigGame holds configs that are valid for the whole game
3131
type ConfigGame struct {
32-
YellowCardDuration time.Duration `yaml:"yellow-card-duration"`
33-
DefaultDivision Division `yaml:"default-division"`
34-
Normal ConfigSpecial `yaml:"normal"`
35-
Overtime ConfigSpecial `yaml:"overtime"`
36-
TeamChoiceTimeout time.Duration `yaml:"team-choice-timeout"`
37-
DefaultGeometry map[Division]*ConfigGeometry `yaml:"default-geometry"`
32+
YellowCardDuration time.Duration `yaml:"yellow-card-duration"`
33+
DefaultDivision Division `yaml:"default-division"`
34+
Normal ConfigSpecial `yaml:"normal"`
35+
Overtime ConfigSpecial `yaml:"overtime"`
36+
TeamChoiceTimeout time.Duration `yaml:"team-choice-timeout"`
37+
DefaultGeometry map[Division]*ConfigGeometry `yaml:"default-geometry"`
38+
MultipleCardStep int `yaml:"multiple-card-step"`
39+
MultipleFoulStep int `yaml:"multiple-foul-step"`
40+
MultiplePlacementFailures int `yaml:"multiple-placement-failures"`
3841
}
3942

4043
// ConfigPublish holds configs for publishing the state and commands to the teams
@@ -94,6 +97,9 @@ func LoadConfig(fileName string) (config Config, err error) {
9497
func DefaultConfig() (c Config) {
9598
c.Publish.Address = "224.5.23.1:10003"
9699
c.Game.YellowCardDuration = 2 * time.Minute
100+
c.Game.MultipleCardStep = 3
101+
c.Game.MultipleFoulStep = 3
102+
c.Game.MultiplePlacementFailures = 5
97103

98104
c.Game.Normal.HalfDuration = 5 * time.Minute
99105
c.Game.Normal.HalfTimeDuration = 5 * time.Minute

internal/app/controller/engine.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func (e *Engine) processGameEvent(event *GameEvent) error {
590590
}
591591

592592
func (e *Engine) FoulCounterIncremented(team Team) {
593-
if e.State.TeamState[team].FoulCounter%3 == 0 {
593+
if e.State.TeamState[team].FoulCounter%e.config.MultipleFoulStep == 0 {
594594
teamProto := team.toProto()
595595
event := GameEvent{Type: GameEventMultipleFouls,
596596
Details: GameEventDetails{MultipleFouls: &refproto.GameEvent_MultipleFouls{ByTeam: &teamProto}}}
@@ -602,7 +602,7 @@ func (e *Engine) FoulCounterIncremented(team Team) {
602602

603603
func (e *Engine) CardNumberIncremented(team Team) {
604604
cards := e.State.TeamState[team].YellowCards + e.State.TeamState[team].RedCards
605-
if cards%3 == 0 {
605+
if cards%e.config.MultipleCardStep == 0 {
606606
teamProto := team.toProto()
607607
event := GameEvent{Type: GameEventMultipleCards,
608608
Details: GameEventDetails{MultipleCards: &refproto.GameEvent_MultipleCards{ByTeam: &teamProto}}}
@@ -613,7 +613,7 @@ func (e *Engine) CardNumberIncremented(team Team) {
613613
}
614614

615615
func (e *Engine) PlacementFailuresIncremented(team Team) {
616-
if e.State.TeamState[team].BallPlacementFailures >= 5 {
616+
if e.State.TeamState[team].BallPlacementFailures >= e.config.MultiplePlacementFailures {
617617
teamProto := team.toProto()
618618
event := GameEvent{Type: GameEventMultiplePlacementFailures,
619619
Details: GameEventDetails{MultiplePlacementFailures: &refproto.GameEvent_MultiplePlacementFailures{ByTeam: &teamProto}}}

0 commit comments

Comments
 (0)