Skip to content

Commit da5e9f9

Browse files
committed
Add an offset for checking recent committed fouls for invalid goal check
1 parent 34680b1 commit da5e9f9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/app/statemachine/change_gameevent.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,17 @@ func (s *StateMachine) isGoalValid(newState *state.State, gameEvent *state.GameE
266266
return
267267
}
268268

269-
// 3. The team did not commit any non stopping foul since the teams robots last touched the ball.
269+
// 3. The team did not commit any non-stopping foul since the teams robots last touched the ball.
270270
var recentlyCommittedFouls []state.GameEvent_Type
271+
var gracePeriod = 2 * time.Second
271272
for _, foul := range newState.TeamInfo(byTeam).Fouls {
272273
if foul.CausedByGameEvent != nil &&
273274
foul.Timestamp != nil &&
274275
gameEvent.GetPossibleGoal().LastTouchByTeam != nil &&
275276
isNonStoppingFoul(*foul.CausedByGameEvent.Type) &&
276-
foul.Timestamp.AsTime().After(microTimestampToTime(*gameEvent.GetPossibleGoal().LastTouchByTeam)) {
277+
// add some time offset: If a bot committed a foul by touching ball inside the penalty area and scores
278+
// a goal shortly afterwards, the foul would have been before lastTouchedByTeam
279+
foul.Timestamp.AsTime().Add(gracePeriod).After(microTimestampToTime(*gameEvent.GetPossibleGoal().LastTouchByTeam)) {
277280
recentlyCommittedFouls = append(recentlyCommittedFouls, *foul.CausedByGameEvent.Type)
278281
}
279282
}

0 commit comments

Comments
 (0)