Skip to content

Commit

Permalink
Remember random placing team for the whole STOP phase
Browse files Browse the repository at this point in the history
Otherwise, when auto_continue is switched off, a new random team is generated continuously, spamming the log and toggling in UI.
  • Loading branch information
g3force committed Jun 18, 2023
1 parent 9f0ce30 commit 3b5d102
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions internal/app/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Engine struct {
botNumberProcessor BotNumberProcessor
tickChanProvider func() <-chan time.Time
rand *rand.Rand
randomPlacingTeam state.Team
}

// NewEngine creates a new engine
Expand Down Expand Up @@ -74,6 +75,7 @@ func NewEngine(gameConfig config.Game, engineConfig config.Engine) (e *Engine) {
return time.After(25 * time.Millisecond)
}
e.rand = rand.New(rand.NewSource(time.Now().Unix()))
e.randomPlacingTeam = state.Team_UNKNOWN
return
}

Expand Down
12 changes: 9 additions & 3 deletions internal/app/engine/process_continue_next_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ func (e *Engine) nextActions() (actions []*ContinueAction, hints []*ContinueHint
actions = append(actions, e.createNextCommandContinueAction(ContinueAction_FREE_KICK, state.Team_YELLOW))
actions = append(actions, e.createNextCommandContinueAction(ContinueAction_FREE_KICK, state.Team_BLUE))
}
} else {
// reset random placing team
e.randomPlacingTeam = state.Team_UNKNOWN
}

if *e.currentState.Command.Type == state.Command_HALT {
Expand Down Expand Up @@ -309,9 +312,12 @@ func (e *Engine) ballPlacementTeam() state.Team {
teamInFavor = *e.currentState.NextCommand.ForTeam
}
if teamInFavor.Unknown() {
// select a team by 50% chance (for example for force start)
teamInFavor = e.randomTeam()
log.Printf("No team in favor. Chose one randomly.")
if e.randomPlacingTeam.Unknown() {
// select a team by 50% chance (for example for force start)
e.randomPlacingTeam = e.randomTeam()
log.Printf("No team in favor. Chose one randomly: %v", e.randomPlacingTeam)
}
teamInFavor = e.randomPlacingTeam
}

if e.currentState.TeamInfo(teamInFavor).BallPlacementAllowed() {
Expand Down

0 comments on commit 3b5d102

Please sign in to comment.