@@ -338,24 +338,45 @@ func (s *StateMachine) nextCommandForEvent(newState *state.State, gameEvent *sta
338338 state .GameEvent_PENALTY_KICK_FAILED ,
339339 state .GameEvent_POSSIBLE_GOAL ,
340340 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+ )
342345 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+ )
344350 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+ )
346355 case state .GameEvent_NO_PROGRESS_IN_GAME ,
347356 state .GameEvent_TOO_MANY_ROBOTS :
348357 return state .NewCommand (state .Command_FORCE_START , state .Team_UNKNOWN )
349358 case state .GameEvent_EMERGENCY_STOP :
350359 if newState .NextCommand != nil {
351360 return newState .NextCommand
352361 }
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+ )
354366 default :
355367 return newState .NextCommand
356368 }
357369}
358370
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+
359380// incrementsFoulCounter checks if the game event increments the foul counter
360381func incrementsFoulCounter (currentState * state.State , gameEvent * state.GameEvent ) bool {
361382 switch * gameEvent .Type {
0 commit comments