Skip to content

Commit 2deeea5

Browse files
committed
[feature] Automatically increment the ball placement failure counter
1 parent f76b614 commit 2deeea5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

internal/app/controller/engine.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,15 @@ func (e *Engine) processGameEvent(event *GameEvent) error {
559559
e.addCard(&EventCard{Type: CardTypeRed, ForTeam: team, Operation: CardOperationAdd}, team, 0)
560560
}
561561

562+
if event.IncrementsBallPlacementFailureCounter() {
563+
team := event.ByTeam()
564+
if team.Unknown() {
565+
return errors.New("Missing team in game event")
566+
}
567+
e.State.TeamState[team].BallPlacementFailures++
568+
e.PlacementFailuresIncremented(team)
569+
}
570+
562571
e.State.PlacementPos = e.BallPlacementPos()
563572

564573
if e.State.GameState() != GameStateHalted && !event.IsContinued() && !event.IsSecondary() {

internal/app/controller/gameEvent.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ func (e GameEvent) AddsRedCard() bool {
105105
return false
106106
}
107107

108+
func (e GameEvent) IncrementsBallPlacementFailureCounter() bool {
109+
switch e.Type {
110+
case GameEventPlacementFailedByTeamInFavor,
111+
GameEventPlacementFailedByOpponent:
112+
return true
113+
}
114+
return false
115+
}
116+
108117
// IsSecondary checks if this game event is a secondary one that does not influence the next referee command
109118
func (e GameEvent) IsSecondary() bool {
110119
switch e.Type {

0 commit comments

Comments
 (0)