@@ -4,7 +4,10 @@ import (
44 "fmt"
55 "github.com/RoboCup-SSL/ssl-game-controller/internal/app/geom"
66 "github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
7+ "github.com/RoboCup-SSL/ssl-game-controller/pkg/timer"
78 "google.golang.org/protobuf/types/known/timestamppb"
9+ "strings"
10+ "time"
811)
912
1013const distanceToBallDuringPenalty = 1.0
@@ -28,7 +31,11 @@ func (e *Engine) createNextCommandContinueAction(
2831 readyAt = nil
2932 } else {
3033 if lastReadyAt == nil {
31- readyAt = timestamppb .New (e .timeProvider ().Add (e .gameConfig .PreparationTimeBeforeResume ))
34+ if e .placementSucceededRecently () {
35+ readyAt = timestamppb .New (e .timeProvider ())
36+ } else {
37+ readyAt = timestamppb .New (e .timeProvider ().Add (e .gameConfig .PreparationTimeBeforeResume ))
38+ }
3239 } else {
3340 readyAt = lastReadyAt
3441 }
@@ -53,6 +60,20 @@ func (e *Engine) createNextCommandContinueAction(
5360 }
5461}
5562
63+ func (e * Engine ) placementSucceededRecently () bool {
64+ events := e .currentState .FindGameEvents (state .GameEvent_PLACEMENT_SUCCEEDED )
65+ for _ , event := range events {
66+ if event .CreatedTimestamp == nil {
67+ continue
68+ }
69+ placementSucceededTime := timer .TimestampMicroToTime (event .GetCreatedTimestamp ())
70+ if e .timeProvider ().Sub (placementSucceededTime ) < time .Second {
71+ return true
72+ }
73+ }
74+ return false
75+ }
76+
5677func (e * Engine ) LastContinueAction (actionType ContinueAction_Type ) * ContinueAction {
5778 for _ , action := range e .gcState .ContinueActions {
5879 if * action .Type == actionType {
@@ -175,9 +196,23 @@ func (e *Engine) readyToContinueFromStop() (issues []string) {
175196 issues = append (issues , "Blue team has too many robots" )
176197 }
177198 radius := e .gameConfig .DistanceToBallInStop + robotRadius - distanceThreshold
178- robotNearBall := e .findRobotInsideRadius (e .trackerStateGc .Robots , e .trackerStateGc .Ball .Pos .ToVector2 (), radius )
179- if robotNearBall != nil {
180- issues = append (issues , fmt .Sprintf ("Robot %s is too close to ball" , robotNearBall .Id .PrettyString ()))
199+
200+ var robots []* Robot
201+ if e .currentState .NextCommand != nil && * e .currentState .NextCommand .Type == state .Command_DIRECT {
202+ // Only check for opponent teams robots
203+ // This is not strictly correct, but necessary to continue directly after a ball placement, without
204+ // waiting for robots to move out of the stop radius.
205+ robots = robotsOfTeam (e .trackerStateGc .Robots , e .currentState .NextCommand .ForTeam .Opposite ())
206+ } else {
207+ robots = e .trackerStateGc .Robots
208+ }
209+ robotsNearBall := e .findRobotInsideRadius (robots , e .trackerStateGc .Ball .Pos .ToVector2 (), radius )
210+ if len (robotsNearBall ) > 0 {
211+ var robotsStr []string
212+ for _ , robot := range robotsNearBall {
213+ robotsStr = append (robotsStr , robot .Id .PrettyString ())
214+ }
215+ issues = append (issues , fmt .Sprintf ("Robots too close to ball: %s" , strings .Join (robotsStr , ", " )))
181216 }
182217 if e .currentState .PlacementPos != nil {
183218 ballToPlacementPosDist := e .currentState .PlacementPos .DistanceTo (e .trackerStateGc .Ball .Pos .ToVector2 ())
@@ -192,6 +227,15 @@ func (e *Engine) readyToContinueFromStop() (issues []string) {
192227 return
193228}
194229
230+ func robotsOfTeam (robots []* Robot , team state.Team ) (teamRobots []* Robot ) {
231+ for _ , robot := range robots {
232+ if * robot .Id .Team == team {
233+ teamRobots = append (teamRobots , robot )
234+ }
235+ }
236+ return
237+ }
238+
195239func (e * Engine ) penaltyKeeperId () * state.RobotId {
196240 forTeam := e .currentState .Command .ForTeam .Opposite ()
197241 teamInfo := e .currentState .TeamState [forTeam .String ()]
0 commit comments