Skip to content

Commit bab4c97

Browse files
committed
[bugfix] Duplicate game events do not inc foul counter within 5s
Especially for use with more than one autoRef and without majority vote.
1 parent bcbe84f commit bab4c97

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

internal/app/controller/engine.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,9 @@ func (e *Engine) processGameEvent(event *GameEvent) error {
682682
e.LogIgnoredGameEvent(*event)
683683
return nil
684684
}
685-
e.AddGameEvent(*event)
685+
event.SetOccurred(e.TimeProvider())
686686

687-
if event.IncrementsFoulCounter() {
687+
if !e.State.MatchesRecentGameEvent(event) && event.IncrementsFoulCounter() {
688688
team := event.ByTeam()
689689
if team.Unknown() {
690690
e.State.TeamState[TeamYellow].FoulCounter++
@@ -697,6 +697,8 @@ func (e *Engine) processGameEvent(event *GameEvent) error {
697697
}
698698
}
699699

700+
e.AddGameEvent(*event)
701+
700702
if event.AddsYellowCard() {
701703
team := event.ByTeam()
702704
if team.Unknown() {

internal/app/controller/gameEvent.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/RoboCup-SSL/ssl-game-controller/pkg/refproto"
77
"log"
88
"reflect"
9+
"time"
910
)
1011

1112
type GameEventType string
@@ -113,9 +114,18 @@ func (g GameEventType) Valid() bool {
113114

114115
// GameEvent combines the type of a game event with the corresponding detail structures
115116
type GameEvent struct {
116-
Type GameEventType `json:"type"`
117-
Details GameEventDetails `json:"details"`
118-
Origins []string `json:"origins"`
117+
Type GameEventType `json:"type"`
118+
Details GameEventDetails `json:"details"`
119+
Origins []string `json:"origins"`
120+
occurred time.Time `json:"-"`
121+
}
122+
123+
func (e *GameEvent) SetOccurred(occurred time.Time) {
124+
e.occurred = occurred
125+
}
126+
127+
func (e GameEvent) Occurred() time.Time {
128+
return e.occurred
119129
}
120130

121131
// String converts the game event into a string

internal/app/controller/state.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,16 @@ func (s *State) GetFirstGameEvent(gameEventType GameEventType) *GameEvent {
571571
return nil
572572
}
573573

574+
func (s *State) MatchesRecentGameEvent(event *GameEvent) bool {
575+
for _, gameEvent := range s.GameEvents {
576+
if gameEvent.Type == event.Type &&
577+
event.Occurred().Sub(gameEvent.Occurred()) < 5*time.Second {
578+
return true
579+
}
580+
}
581+
return false
582+
}
583+
574584
// Location is a two-dimensional coordinate
575585
type Location struct {
576586
X float64 `json:"x" yaml:"x"`

0 commit comments

Comments
 (0)