@@ -338,24 +338,45 @@ func (s *StateMachine) nextCommandForEvent(newState *state.State, gameEvent *sta
338
338
state .GameEvent_PENALTY_KICK_FAILED ,
339
339
state .GameEvent_POSSIBLE_GOAL ,
340
340
state .GameEvent_INVALID_GOAL :
341
- return state .NewCommand (state .Command_DIRECT , gameEvent .ByTeam ().Opposite ())
341
+ return lastCommandOnUnknownTeam (
342
+ newState .NextCommand ,
343
+ state .NewCommand (state .Command_DIRECT , gameEvent .ByTeam ().Opposite ()),
344
+ )
342
345
case state .GameEvent_DEFENDER_IN_DEFENSE_AREA :
343
- return state .NewCommand (state .Command_PENALTY , gameEvent .ByTeam ().Opposite ())
346
+ return lastCommandOnUnknownTeam (
347
+ newState .NextCommand ,
348
+ state .NewCommand (state .Command_PENALTY , gameEvent .ByTeam ().Opposite ()),
349
+ )
344
350
case state .GameEvent_GOAL :
345
- return state .NewCommand (state .Command_KICKOFF , gameEvent .ByTeam ().Opposite ())
351
+ return lastCommandOnUnknownTeam (
352
+ newState .NextCommand ,
353
+ state .NewCommand (state .Command_KICKOFF , gameEvent .ByTeam ().Opposite ()),
354
+ )
346
355
case state .GameEvent_NO_PROGRESS_IN_GAME ,
347
356
state .GameEvent_TOO_MANY_ROBOTS :
348
357
return state .NewCommand (state .Command_FORCE_START , state .Team_UNKNOWN )
349
358
case state .GameEvent_EMERGENCY_STOP :
350
359
if newState .NextCommand != nil {
351
360
return newState .NextCommand
352
361
}
353
- return state .NewCommand (state .Command_DIRECT , gameEvent .ByTeam ().Opposite ())
362
+ return lastCommandOnUnknownTeam (
363
+ newState .NextCommand ,
364
+ state .NewCommand (state .Command_DIRECT , gameEvent .ByTeam ().Opposite ()),
365
+ )
354
366
default :
355
367
return newState .NextCommand
356
368
}
357
369
}
358
370
371
+ func lastCommandOnUnknownTeam (lastCommand , newCommand * state.Command ) * state.Command {
372
+ if newCommand .ForTeam .Unknown () {
373
+ // no (new) next command, if the team is unknown
374
+ // this can happen if an autoRef majority matched by type, but not by team
375
+ return lastCommand
376
+ }
377
+ return newCommand
378
+ }
379
+
359
380
// incrementsFoulCounter checks if the game event increments the foul counter
360
381
func incrementsFoulCounter (currentState * state.State , gameEvent * state.GameEvent ) bool {
361
382
switch * gameEvent .Type {
0 commit comments