@@ -4,7 +4,10 @@ import (
4
4
"fmt"
5
5
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/geom"
6
6
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
7
+ "github.com/RoboCup-SSL/ssl-game-controller/pkg/timer"
7
8
"google.golang.org/protobuf/types/known/timestamppb"
9
+ "strings"
10
+ "time"
8
11
)
9
12
10
13
const distanceToBallDuringPenalty = 1.0
@@ -28,7 +31,11 @@ func (e *Engine) createNextCommandContinueAction(
28
31
readyAt = nil
29
32
} else {
30
33
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
+ }
32
39
} else {
33
40
readyAt = lastReadyAt
34
41
}
@@ -53,6 +60,20 @@ func (e *Engine) createNextCommandContinueAction(
53
60
}
54
61
}
55
62
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
+
56
77
func (e * Engine ) LastContinueAction (actionType ContinueAction_Type ) * ContinueAction {
57
78
for _ , action := range e .gcState .ContinueActions {
58
79
if * action .Type == actionType {
@@ -175,9 +196,23 @@ func (e *Engine) readyToContinueFromStop() (issues []string) {
175
196
issues = append (issues , "Blue team has too many robots" )
176
197
}
177
198
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 , ", " )))
181
216
}
182
217
if e .currentState .PlacementPos != nil {
183
218
ballToPlacementPosDist := e .currentState .PlacementPos .DistanceTo (e .trackerStateGc .Ball .Pos .ToVector2 ())
@@ -192,6 +227,15 @@ func (e *Engine) readyToContinueFromStop() (issues []string) {
192
227
return
193
228
}
194
229
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
+
195
239
func (e * Engine ) penaltyKeeperId () * state.RobotId {
196
240
forTeam := e .currentState .Command .ForTeam .Opposite ()
197
241
teamInfo := e .currentState .TeamState [forTeam .String ()]
0 commit comments