Skip to content

Commit 3b5d102

Browse files
committed
Remember random placing team for the whole STOP phase
Otherwise, when auto_continue is switched off, a new random team is generated continuously, spamming the log and toggling in UI.
1 parent 9f0ce30 commit 3b5d102

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

internal/app/engine/engine.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type Engine struct {
4343
botNumberProcessor BotNumberProcessor
4444
tickChanProvider func() <-chan time.Time
4545
rand *rand.Rand
46+
randomPlacingTeam state.Team
4647
}
4748

4849
// NewEngine creates a new engine
@@ -74,6 +75,7 @@ func NewEngine(gameConfig config.Game, engineConfig config.Engine) (e *Engine) {
7475
return time.After(25 * time.Millisecond)
7576
}
7677
e.rand = rand.New(rand.NewSource(time.Now().Unix()))
78+
e.randomPlacingTeam = state.Team_UNKNOWN
7779
return
7880
}
7981

internal/app/engine/process_continue_next_action.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ func (e *Engine) nextActions() (actions []*ContinueAction, hints []*ContinueHint
164164
actions = append(actions, e.createNextCommandContinueAction(ContinueAction_FREE_KICK, state.Team_YELLOW))
165165
actions = append(actions, e.createNextCommandContinueAction(ContinueAction_FREE_KICK, state.Team_BLUE))
166166
}
167+
} else {
168+
// reset random placing team
169+
e.randomPlacingTeam = state.Team_UNKNOWN
167170
}
168171

169172
if *e.currentState.Command.Type == state.Command_HALT {
@@ -309,9 +312,12 @@ func (e *Engine) ballPlacementTeam() state.Team {
309312
teamInFavor = *e.currentState.NextCommand.ForTeam
310313
}
311314
if teamInFavor.Unknown() {
312-
// select a team by 50% chance (for example for force start)
313-
teamInFavor = e.randomTeam()
314-
log.Printf("No team in favor. Chose one randomly.")
315+
if e.randomPlacingTeam.Unknown() {
316+
// select a team by 50% chance (for example for force start)
317+
e.randomPlacingTeam = e.randomTeam()
318+
log.Printf("No team in favor. Chose one randomly: %v", e.randomPlacingTeam)
319+
}
320+
teamInFavor = e.randomPlacingTeam
315321
}
316322

317323
if e.currentState.TeamInfo(teamInFavor).BallPlacementAllowed() {

0 commit comments

Comments
 (0)