@@ -170,6 +170,10 @@ func (s *StateMachine) processChangeAddGameEvent(newState *state.State, change *
170
170
* newState .TeamInfo (byTeam ).BallPlacementFailuresReached = * newState .TeamInfo (byTeam ).BallPlacementFailures >= s .gameConfig .MultiplePlacementFailures
171
171
if s .allTeamsFailedPlacement (newState ) {
172
172
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
+ }
173
177
changes = append (changes , s .createCommandChange (state .NewCommandNeutral (state .Command_HALT )))
174
178
} else {
175
179
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 {
483
487
// allTeamsFailedPlacement returns true if all teams failed placing the ball
484
488
// It takes into account, how many teams are able to place the ball and how many failures happened
485
489
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 )
492
491
493
492
failures := 0
494
493
for _ , e := range newState .GameEvents {
@@ -502,6 +501,16 @@ func (s *StateMachine) allTeamsFailedPlacement(newState *state.State) bool {
502
501
return false
503
502
}
504
503
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
+
505
514
func goTime (timestamp * timestamp.Timestamp ) time.Time {
506
515
goTime , err := ptypes .Timestamp (timestamp )
507
516
if err != nil {
0 commit comments