Skip to content

Commit 51425dc

Browse files
committed
[feature] Add game event for too many robots and start bot substitution
1 parent 23ed20b commit 51425dc

File tree

7 files changed

+293
-129
lines changed

7 files changed

+293
-129
lines changed

internal/app/controller/gameEvent.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const (
1818
GameEventPlacementFailedByTeamInFavor GameEventType = "placementFailedByTeamInFavor"
1919
GameEventPlacementFailedByOpponent GameEventType = "placementFailedByOpponent"
2020
GameEventPlacementSucceeded GameEventType = "placementSucceeded"
21-
GameEventBotSubstitution GameEventType = "gameEventBotSubstitution"
21+
GameEventBotSubstitution GameEventType = "botSubstitution"
22+
GameEventTooManyRobots GameEventType = "tooManyRobots"
2223

2324
GameEventBallLeftFieldTouchLine GameEventType = "ballLeftFieldTouchLine"
2425
GameEventBallLeftFieldGoalLine GameEventType = "ballLeftFieldGoalLine"
@@ -63,8 +64,8 @@ type GameEvent struct {
6364
Details GameEventDetails `json:"details"`
6465
}
6566

66-
func (m GameEvent) String() string {
67-
b, _ := json.Marshal(&m)
67+
func (e GameEvent) String() string {
68+
b, _ := json.Marshal(&e)
6869
return string(b)
6970
}
7071

@@ -106,6 +107,8 @@ func AllGameEvents() []GameEventType {
106107
GameEventPlacementFailedByOpponent,
107108
GameEventPlacementSucceeded,
108109
GameEventPrepared,
110+
GameEventBotSubstitution,
111+
GameEventTooManyRobots,
109112
}
110113
}
111114

@@ -185,7 +188,8 @@ func (e GameEvent) IsSecondary() bool {
185188
GameEventPlacementFailedByOpponent,
186189
GameEventPlacementSucceeded,
187190
GameEventPrepared,
188-
GameEventBotSubstitution:
191+
GameEventBotSubstitution,
192+
GameEventTooManyRobots:
189193
return true
190194
}
191195
return false
@@ -290,8 +294,10 @@ func (e GameEvent) ToProto() *refproto.GameEvent {
290294
protoEvent.Event = &refproto.GameEvent_Prepared_{Prepared: e.Details.Prepared}
291295
case GameEventBotSubstitution:
292296
protoEvent.Event = &refproto.GameEvent_BotSubstitution_{BotSubstitution: e.Details.BotSubstitution}
297+
case GameEventTooManyRobots:
298+
protoEvent.Event = &refproto.GameEvent_TooManyRobots_{TooManyRobots: e.Details.TooManyRobots}
293299
default:
294-
log.Printf("Warn: Could not map game e %v", e.Type)
300+
log.Printf("Warn: Could not map game event %v", e.Type)
295301
return nil
296302
}
297303
return protoEvent
@@ -336,6 +342,7 @@ type GameEventDetails struct {
336342
PlacementSucceeded *refproto.GameEvent_PlacementSucceeded `json:"placementSucceeded,omitempty"`
337343
Prepared *refproto.GameEvent_Prepared `json:"prepared,omitempty"`
338344
BotSubstitution *refproto.GameEvent_BotSubstitution `json:"botSubstitution,omitempty"`
345+
TooManyRobots *refproto.GameEvent_TooManyRobots `json:"tooManyRobots,omitempty"`
339346
}
340347

341348
func (d GameEventDetails) EventType() GameEventType {
@@ -450,6 +457,9 @@ func (d GameEventDetails) EventType() GameEventType {
450457
if d.BotSubstitution != nil {
451458
return GameEventBotSubstitution
452459
}
460+
if d.TooManyRobots != nil {
461+
return GameEventTooManyRobots
462+
}
453463
return GameEventNone
454464
}
455465

@@ -649,6 +659,9 @@ func (d GameEventDetails) Description() string {
649659
if d.BotSubstitution != nil {
650660
return ""
651661
}
662+
if d.TooManyRobots != nil {
663+
return ""
664+
}
652665
return ""
653666
}
654667

@@ -690,5 +703,6 @@ func NewGameEventDetails(event refproto.GameEvent) (d GameEventDetails) {
690703
d.PlacementSucceeded = event.GetPlacementSucceeded()
691704
d.Prepared = event.GetPrepared()
692705
d.BotSubstitution = event.GetBotSubstitution()
706+
d.TooManyRobots = event.GetTooManyRobots()
693707
return
694708
}

internal/app/controller/state.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,26 @@ func (s State) GameState() GameState {
339339
}
340340

341341
func (s State) BotSubstitutionIntend() Team {
342-
if s.TeamState[TeamYellow].BotSubstitutionIntend && s.TeamState[TeamBlue].BotSubstitutionIntend {
342+
blue := false
343+
yellow := false
344+
for _, event := range s.GameEvents {
345+
if event.Type == GameEventTooManyRobots {
346+
blue = blue || event.ByTeam() == TeamBlue
347+
yellow = yellow || event.ByTeam() == TeamYellow
348+
break
349+
}
350+
}
351+
352+
yellow = yellow || s.TeamState[TeamYellow].BotSubstitutionIntend
353+
blue = blue || s.TeamState[TeamBlue].BotSubstitutionIntend
354+
355+
if yellow && blue {
343356
return TeamBoth
344357
}
345-
if s.TeamState[TeamYellow].BotSubstitutionIntend {
358+
if yellow {
346359
return TeamYellow
347360
}
348-
if s.TeamState[TeamBlue].BotSubstitutionIntend {
361+
if blue {
349362
return TeamBlue
350363
}
351364
return TeamUnknown

0 commit comments

Comments
 (0)