Skip to content

Commit 060b79c

Browse files
committed
Give the free kick to the original team, if both teams failed placement
1 parent 21da99c commit 060b79c

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

internal/app/statemachine/change_gameevent.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ func (s *StateMachine) processChangeAddGameEvent(newState *state.State, change *
170170
*newState.TeamInfo(byTeam).BallPlacementFailuresReached = *newState.TeamInfo(byTeam).BallPlacementFailures >= s.gameConfig.MultiplePlacementFailures
171171
if s.allTeamsFailedPlacement(newState) {
172172
log.Printf("Placement failed for all teams. The human ref must place the ball.")
173+
if s.numActiveBallPlacementTeams(newState) == 2 {
174+
// both teams failed, switch back to original command
175+
newState.NextCommand = state.NewCommand(state.Command_DIRECT, byTeam.Opposite())
176+
}
173177
changes = append(changes, s.createCommandChange(state.NewCommandNeutral(state.Command_HALT)))
174178
} else {
175179
log.Printf("Placement failed for team %v. Team %v is awarded a free kick and places the ball.", byTeam, byTeam.Opposite())
@@ -483,12 +487,7 @@ func locationForRuleViolation(gameEvent *state.GameEvent) *geom.Vector2 {
483487
// allTeamsFailedPlacement returns true if all teams failed placing the ball
484488
// It takes into account, how many teams are able to place the ball and how many failures happened
485489
func (s *StateMachine) allTeamsFailedPlacement(newState *state.State) bool {
486-
possibleFailures := 0
487-
for _, team := range state.BothTeams() {
488-
if newState.TeamInfo(team).BallPlacementAllowed() {
489-
possibleFailures++
490-
}
491-
}
490+
possibleFailures := s.numActiveBallPlacementTeams(newState)
492491

493492
failures := 0
494493
for _, e := range newState.GameEvents {
@@ -502,6 +501,16 @@ func (s *StateMachine) allTeamsFailedPlacement(newState *state.State) bool {
502501
return false
503502
}
504503

504+
func (s *StateMachine) numActiveBallPlacementTeams(newState *state.State) int {
505+
possibleFailures := 0
506+
for _, team := range state.BothTeams() {
507+
if newState.TeamInfo(team).BallPlacementAllowed() {
508+
possibleFailures++
509+
}
510+
}
511+
return possibleFailures
512+
}
513+
505514
func goTime(timestamp *timestamp.Timestamp) time.Time {
506515
goTime, err := ptypes.Timestamp(timestamp)
507516
if err != nil {

0 commit comments

Comments
 (0)