@@ -2,6 +2,7 @@ package engine
2
2
3
3
import (
4
4
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/state"
5
+ "slices"
5
6
)
6
7
7
8
type BallPlacementCoordinator struct {
@@ -23,12 +24,14 @@ func (c *BallPlacementCoordinator) process() {
23
24
}
24
25
25
26
remainingDistance := c .remainingPlacementDistance ()
27
+ nearestOwnRobotDistance := c .nearestOwnRobotDistance ()
26
28
27
29
e .Enqueue (createGameEventChange (state .GameEvent_PLACEMENT_FAILED , & state.GameEvent {
28
30
Event : & state.GameEvent_PlacementFailed_ {
29
31
PlacementFailed : & state.GameEvent_PlacementFailed {
30
- ByTeam : e .currentState .Command .ForTeam ,
31
- RemainingDistance : & remainingDistance ,
32
+ ByTeam : e .currentState .Command .ForTeam ,
33
+ RemainingDistance : & remainingDistance ,
34
+ NearestOwnBotDistance : & nearestOwnRobotDistance ,
32
35
},
33
36
},
34
37
}))
@@ -42,3 +45,25 @@ func (c *BallPlacementCoordinator) remainingPlacementDistance() float32 {
42
45
ballPos := c .gcEngine .trackerStateGc .Ball .Pos .ToVector2 ()
43
46
return float32 (placementPos .DistanceTo (ballPos ))
44
47
}
48
+
49
+ func (c * BallPlacementCoordinator ) nearestOwnRobotDistance () float32 {
50
+ if c .gcEngine .currentState .PlacementPos == nil {
51
+ return - 1
52
+ }
53
+ placementPos := c .gcEngine .currentState .PlacementPos
54
+
55
+ var distances []float32
56
+ for _ , robot := range c .gcEngine .trackerStateGc .Robots {
57
+ if * robot .Id .Team == * c .gcEngine .currentState .Command .ForTeam {
58
+ distance := float32 (robot .Pos .DistanceTo (placementPos ))
59
+ distances = append (distances , distance )
60
+ }
61
+ }
62
+
63
+ if len (distances ) == 0 {
64
+ return - 1
65
+ }
66
+
67
+ slices .Sort (distances )
68
+ return distances [0 ]
69
+ }
0 commit comments