Skip to content

Commit 8238ef7

Browse files
committed
Only raise TOO_MANY_ROBOTS game event while running
1 parent 1cfab68 commit 8238ef7

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

internal/app/engine/engine.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Engine struct {
3434
mutex sync.Mutex
3535
noProgressDetector NoProgressDetector
3636
ballPlacementCoordinator BallPlacementCoordinator
37+
botNumberProcessor BotNumberProcessor
3738
tickChanProvider func() <-chan time.Time
3839
}
3940

@@ -59,6 +60,7 @@ func NewEngine(gameConfig config.Game, engineConfig config.Engine) (e *Engine) {
5960
e.trackerLastUpdate = map[string]time.Time{}
6061
e.noProgressDetector = NoProgressDetector{gcEngine: e}
6162
e.ballPlacementCoordinator = BallPlacementCoordinator{gcEngine: e}
63+
e.botNumberProcessor = BotNumberProcessor{gcEngine: e}
6264
e.tickChanProvider = func() <-chan time.Time {
6365
return time.After(25 * time.Millisecond)
6466
}

internal/app/engine/process_botremoved.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,32 @@ import (
77
"time"
88
)
99

10-
func (e *Engine) processBotNumber() {
11-
if !e.IsGameEventEnabled(state.GameEvent_TOO_MANY_ROBOTS) {
10+
type BotNumberProcessor struct {
11+
gcEngine *Engine
12+
lastTime *time.Time
13+
}
14+
15+
func (p *BotNumberProcessor) processBotNumber() {
16+
17+
if !p.gcEngine.currentState.Command.IsRunning() ||
18+
!p.gcEngine.IsGameEventEnabled(state.GameEvent_TOO_MANY_ROBOTS) {
19+
p.lastTime = nil
20+
return
21+
}
22+
23+
if p.lastTime == nil {
24+
p.lastTime = new(time.Time)
25+
*p.lastTime = p.gcEngine.timeProvider()
26+
return
27+
}
28+
29+
timeSinceLastProgress := p.gcEngine.timeProvider().Sub(*p.lastTime)
30+
if timeSinceLastProgress < 2*time.Second {
1231
return
1332
}
1433

1534
for _, team := range state.BothTeams() {
16-
e.processBotNumberPerTeam(team)
35+
p.gcEngine.processBotNumberPerTeam(team)
1736
}
1837
}
1938

internal/app/engine/process_tick.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (e *Engine) processTick() {
6060
e.noProgressDetector.process()
6161
e.ballPlacementCoordinator.process()
6262
e.processContinue()
63-
e.processBotNumber()
63+
e.botNumberProcessor.processBotNumber()
6464
e.processPenalty()
6565
e.processProposals()
6666
e.processTrackerSources()

0 commit comments

Comments
 (0)