From 3a623d909278d1bbd5d70c8fd1840ced9305020b Mon Sep 17 00:00:00 2001 From: Nicolai Ommer Date: Sun, 24 Apr 2022 13:22:29 +0200 Subject: [PATCH] Automatically request robot substitution on too many robots --- internal/app/engine/process_continue.go | 6 ++++++ internal/app/statemachine/change_gameevent.go | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/internal/app/engine/process_continue.go b/internal/app/engine/process_continue.go index b3b1675a..8543004b 100644 --- a/internal/app/engine/process_continue.go +++ b/internal/app/engine/process_continue.go @@ -118,6 +118,12 @@ func (e *Engine) readyToContinuePenalty() (issues []string) { } func (e *Engine) readyToContinueFromStop() (issues []string) { + for _, team := range state.BothTeams() { + if e.currentState.TeamInfo(team).RequestsBotSubstitutionSince != nil { + // next action is robot substitution, no need to check the other issues + return + } + } if e.tooManyRobots(state.Team_YELLOW) { issues = append(issues, "Yellow team has too many robots") } diff --git a/internal/app/statemachine/change_gameevent.go b/internal/app/statemachine/change_gameevent.go index f776d41f..cfa76a0d 100644 --- a/internal/app/statemachine/change_gameevent.go +++ b/internal/app/statemachine/change_gameevent.go @@ -7,6 +7,7 @@ import ( "github.com/RoboCup-SSL/ssl-game-controller/internal/app/state" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/durationpb" + "google.golang.org/protobuf/types/known/timestamppb" "log" "time" ) @@ -126,6 +127,20 @@ func (s *StateMachine) processChangeAddGameEvent(newState *state.State, change * changes = append(changes, s.createCommandChange(state.NewCommandNeutral(state.Command_HALT))) } + // too many robots + if *gameEvent.Type == state.GameEvent_TOO_MANY_ROBOTS { + byTeam := *gameEvent.GetTooManyRobots().ByTeam + if byTeam.Known() { + log.Printf("Team %s has too many robots. Requesting robot substition for them", byTeam) + newState.TeamInfo(byTeam).RequestsBotSubstitutionSince = timestamppb.New(s.timeProvider()) + } else { + log.Printf("Too many robots, but no information on team. Requesting for both") + for _, team := range state.BothTeams() { + newState.TeamInfo(team).RequestsBotSubstitutionSince = timestamppb.New(s.timeProvider()) + } + } + } + // challenge flag if *gameEvent.Type == state.GameEvent_CHALLENGE_FLAG { log.Printf("Reduce number of timeouts for %v by one for challenge flag", byTeam)