Skip to content

Commit d2a9270

Browse files
authored
Merge pull request #6 from CLSFramework/starter_develop_bool
Starter develop bool
2 parents 88c39ef + a253d07 commit d2a9270

36 files changed

+2956
-94
lines changed

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,93 @@ TODO
288288

289289
TODO
290290

291+
## Decision Making
292+
293+
```mermaid
294+
flowchart TD
295+
subgraph SamplePlayerAgent
296+
SamplePlayerAgent_update_actions[update_actions]
297+
end
298+
299+
subgraph FormationStrategy
300+
FormationStrategy_update[update]
301+
end
302+
303+
subgraph StarterStrategy
304+
StarterStrategy_update[update]
305+
end
306+
307+
subgraph DecisionMaker
308+
DecisionMaker_make_decision[make_decision]
309+
end
310+
311+
subgraph PlayOnDecisionMaker
312+
PlayOnDecisionMaker_make_decision[make_decision]
313+
end
314+
subgraph SetPlayDecisionMaker
315+
SetPlayDecisionMaker_make_decision[make_decision]
316+
end
317+
subgraph PenaltyDecisionMaker
318+
PenaltyDecisionMaker_make_decision[make_decision]
319+
end
320+
subgraph GoalieDecisionMaker
321+
GoalieDecisionMaker_make_decision[make_decision]
322+
end
323+
subgraph KickDecisionMaker
324+
KickDecisionMaker_make_decision[make_decision]
325+
end
326+
subgraph MoveDecisionMaker
327+
MoveDecisionMaker_make_decision[make_decision]
328+
end
329+
330+
subgraph BhvKickPlanner
331+
BhvKickPlanner_execute[execute]
332+
end
333+
334+
subgraph BhvStarterKickPlanner
335+
BhvStarterKickPlanner_execute[execute]
336+
end
337+
338+
subgraph BhvSetPlay
339+
BhvSetPlay_execute[execute]
340+
end
341+
342+
subgraph BhvStarterSetPlay
343+
BhvStarterSetPlay_execute[execute]
344+
end
345+
346+
subgraph BhvPenalty
347+
BhvPenalty_execute[execute]
348+
end
349+
350+
subgraph BhvStarterPenalty
351+
BhvStarterPenalty_execute[execute]
352+
end
353+
354+
SamplePlayerAgent_update_actions --> A{is starter?}
355+
A -->|yes| StarterStrategy_update
356+
A -->|no| FormationStrategy_update
357+
SamplePlayerAgent_update_actions --> DecisionMaker_make_decision
358+
DecisionMaker_make_decision --> B{status?}
359+
B --> PlayOnDecisionMaker_make_decision
360+
B --> SetPlayDecisionMaker_make_decision
361+
B --> PenaltyDecisionMaker_make_decision
362+
B --> GoalieDecisionMaker_make_decision
363+
PlayOnDecisionMaker_make_decision --> C{is kickable?}
364+
C -->|yes| KickDecisionMaker_make_decision
365+
C -->|no| MoveDecisionMaker_make_decision
366+
KickDecisionMaker_make_decision --> D{is starter?}
367+
D -->|yes| BhvStarterKickPlanner_execute
368+
D -->|no| BhvKickPlanner_execute
369+
SetPlayDecisionMaker_make_decision --> E{is starter?}
370+
E -->|yes| BhvStarterSetPlay_execute
371+
E -->|no| BhvSetPlay_execute
372+
PenaltyDecisionMaker_make_decision --> F{is starter?}
373+
F -->|yes| BhvStarterPenalty_execute
374+
F -->|no| BhvPenalty_execute
375+
376+
```
377+
291378
## Citation
292379

293380
- [Cross Language Soccer Framework](https://arxiv.org/pdf/2406.05621)

idl/service.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ message PenaltyKickState {
135135
int32 our_score = 5;
136136
int32 their_score = 6;
137137
bool is_kick_taker = 7;
138+
int32 cycle = 8;
138139
}
139140

140141
/**
@@ -172,6 +173,7 @@ message Player {
172173
int32 ball_reach_steps = 28; // How many cycles the player needs to reach the ball.
173174
bool is_tackling = 29; // Whether the player is tackling or not.
174175
int32 type_id = 30; // The type identifier of the player.
176+
RpcVector2D inertia_final_point = 31;
175177
}
176178

177179
/**
@@ -220,6 +222,7 @@ message Self {
220222
CardType card = 39; // The card type of the agent. It can be NO_CARD, YELLOW, or RED.
221223
int32 catch_time = 40; // The time when the last catch command is performed.
222224
float effort = 41; // The effort of the agent. TODO more info
225+
float get_safety_dash_power = 42;
223226
}
224227

225228
/**
@@ -1296,6 +1299,8 @@ message bhv_doForceKick {}
12961299

12971300
message bhv_doHeardPassRecieve {}
12981301

1302+
message bhv_goalieFreeKick {}
1303+
12991304
message PlayerAction {
13001305
oneof action {
13011306
Dash dash = 1;
@@ -1366,6 +1371,7 @@ message PlayerAction {
13661371
bhv_doHeardPassRecieve bhv_do_heard_pass_recieve = 66;
13671372
HeliosBasicTackle helios_basic_tackle = 67;
13681373
Neck_OffensiveInterceptNeck neck_offensive_intercept_neck = 68;
1374+
bhv_goalieFreeKick bhv_goalie_free_kick = 69;
13691375
}
13701376
}
13711377

@@ -1668,6 +1674,7 @@ message ServerParam {
16681674
float goal_area_length = 224;
16691675
float center_circle_r = 225;
16701676
float goal_post_radius = 226;
1677+
float pitch_margin = 227;
16711678
}
16721679

16731680
message PlayerParam {

src/behaviors/bhv_block.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
1+
from typing import TYPE_CHECKING
22
from src.interfaces.IAgent import IAgent
33
from src.utils.convertor import Convertor
44
from pyrusgeom.geom_2d import *
55
from pyrusgeom.soccer_math import *
66
from service_pb2 import *
77
from src.interfaces.IBehavior import IBehavior
88

9+
if TYPE_CHECKING:
10+
from src.sample_player_agent import SamplePlayerAgent
911

1012
class Bhv_Block(IBehavior):
1113
"""
@@ -26,7 +28,7 @@ class Bhv_Block(IBehavior):
2628
def __init__(self):
2729
pass
2830

29-
def execute(self, agent: IAgent) -> bool:
31+
def execute(self, agent: "SamplePlayerAgent") -> bool:
3032
"""
3133
Executes the block behavior for the agent. Predicts the future position of the ball and checks if the agent or any teammate can block it within a certain number of cycles.
3234
Parameters:
@@ -38,9 +40,6 @@ def execute(self, agent: IAgent) -> bool:
3840
- Calculate the first cycle that the agent or a teammate can block the ball.
3941
- If the agent can block the ball, add a Body_GoToPoint action to the agent.
4042
"""
41-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
42-
assert isinstance(agent, SamplePlayerAgent)
43-
4443
agent.logger.debug(f'------ Bhv_Block ------')
4544
wm = agent.wm
4645
sp = agent.server_params

src/behaviors/bhv_kick_planner.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from typing import TYPE_CHECKING
12
from src.interfaces.IBehavior import IBehavior
23
from src.interfaces.IAgent import IAgent
34
from pyrusgeom.soccer_math import *
45
from pyrusgeom.geom_2d import *
56
from service_pb2 import *
67

8+
if TYPE_CHECKING:
9+
from src.sample_player_agent import SamplePlayerAgent
710

811
class BhvKickPlanner(IBehavior):
912
"""
@@ -33,10 +36,8 @@ class BhvKickPlanner(IBehavior):
3336
def __init__(self):
3437
pass
3538

36-
def execute(self, agent: IAgent):
39+
def execute(self, agent: "SamplePlayerAgent"):
3740
agent.logger.debug("--- WithBallDecisionMaker ---")
38-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
39-
assert isinstance(agent, SamplePlayerAgent)
4041

4142
agent.add_action(
4243
PlayerAction(helios_offensive_planner=self._get_helios_offensive_planner(agent))

src/behaviors/bhv_penalty.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
1+
from typing import TYPE_CHECKING
22
from src.interfaces.IAgent import IAgent
33
from src.utils.convertor import Convertor
44
from pyrusgeom.geom_2d import *
55
from pyrusgeom.soccer_math import *
66
from service_pb2 import *
77
from src.interfaces.IBehavior import IBehavior
88

9+
if TYPE_CHECKING:
10+
from src.sample_player_agent import SamplePlayerAgent
911

1012
class BhvPenalty(IBehavior):
1113
def __init__(self):
1214
pass
1315

14-
def execute(self, agent: IAgent) -> bool:
16+
def execute(self, agent: "SamplePlayerAgent"):
1517
agent.logger.debug("BhvPenalty.execute")
16-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
17-
assert isinstance(agent, SamplePlayerAgent)
1818
agent.add_action(PlayerAction(helios_penalty=HeliosPenalty()))

src/behaviors/bhv_setplay.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
1+
from typing import TYPE_CHECKING
22
from src.interfaces.IAgent import IAgent
33
from src.utils.convertor import Convertor
44
from pyrusgeom.geom_2d import *
55
from pyrusgeom.soccer_math import *
66
from service_pb2 import *
77
from src.interfaces.IBehavior import IBehavior
88

9+
if TYPE_CHECKING:
10+
from src.sample_player_agent import SamplePlayerAgent
911

1012
class BhvSetPlay(IBehavior):
1113
def __init__(self):
1214
pass
1315

14-
def execute(self, agent: IAgent) -> bool:
16+
def execute(self, agent: "SamplePlayerAgent"):
1517
agent.logger.debug("BhvSetPlay.execute")
16-
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
17-
assert isinstance(agent, SamplePlayerAgent)
1818
agent.add_action(PlayerAction(helios_set_play=HeliosSetPlay()))
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from src.interfaces.IBehavior import IBehavior
2+
from src.interfaces.IAgent import IAgent
3+
from pyrusgeom.soccer_math import *
4+
from pyrusgeom.geom_2d import *
5+
from src.utils.tools import Tools
6+
from pyrusgeom import vector_2d
7+
from service_pb2 import *
8+
9+
class BhvStarterClearBall():
10+
11+
def __init__(self):
12+
pass
13+
14+
15+
def execute(agent: IAgent):
16+
wm = agent.wm
17+
ball_pos = Vector2D(wm.ball.position.x, wm.ball.position.y)
18+
target = Vector2D(agent.server_params.pitch_half_length, 0.0)
19+
if ball_pos.x() > -25.0 :
20+
if ball_pos.dist(Vector2D(0.0, -agent.server_params.pitch_half_width)) < ball_pos.dist(Vector2D(0.0, agent.server_params.pitch_half_width)) :
21+
target = Vector2D(0.0,-34.0)
22+
else:
23+
target = Vector2D(0.0,34.0)
24+
else :
25+
if abs(ball_pos.y()) < 10 and ball_pos.x() < -10.0 :
26+
if ball_pos.y() > 0.0 :
27+
target = Vector2D(-agent.server_params.pitch_half_length, 20.0)
28+
else :
29+
target = Vector2D(-agent.server_params.pitch_half_length, -20.0)
30+
else:
31+
if ball_pos.y() > 0.0 :
32+
target = Vector2D(ball_pos.x(), 34.0)
33+
else :
34+
target = Vector2D(ball_pos.x(), -34.0)
35+
return PlayerAction(body_smart_kick=Body_SmartKick(target_point=RpcVector2D(x=target.x(), y=target.y()),
36+
first_speed=2.7,
37+
first_speed_threshold=2.7,
38+
max_steps=2))
39+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from src.interfaces.IBehavior import IBehavior
2+
from src.interfaces.IAgent import IAgent
3+
from src.utils.tools import Tools
4+
from pyrusgeom.vector_2d import Vector2D
5+
from pyrusgeom.sector_2d import Sector2D
6+
from service_pb2 import *
7+
8+
9+
class BhvStarterDribble():
10+
11+
def __init__(self):
12+
pass
13+
14+
def execute(agent: IAgent):
15+
wm = agent.wm
16+
ball_pos = Vector2D(wm.ball.position.x, wm.ball.position.y)
17+
dribble_angle = (Vector2D(52.5, 0) - ball_pos).th().degree()
18+
dribble_speed = 0.8
19+
dribble_threshold = 0.7
20+
dribble_sector = Sector2D(ball_pos, 0, 3, dribble_angle - 15, dribble_angle + 15)
21+
22+
if not Tools.ExistOpponentIn(agent , dribble_sector):
23+
Target = Vector2D.polar2vector(3, dribble_angle) + ball_pos
24+
return PlayerAction(body_smart_kick=Body_SmartKick(target_point=RpcVector2D(x=Target.x(), y=Target.y()),
25+
first_speed=dribble_speed,
26+
first_speed_threshold=dribble_threshold,
27+
max_steps=2))
28+
return
29+
30+
31+
32+
33+

src/behaviors/bhv_starter_kick_planner.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,39 @@
33
from pyrusgeom.soccer_math import *
44
from pyrusgeom.geom_2d import *
55
from service_pb2 import *
6-
6+
from src.behaviors.bhv_starter_clearball import BhvStarterClearBall
7+
from src.behaviors.bhv_starter_pass import BhvStarterPass
8+
from src.behaviors.bhv_starter_dribble import BhvStarterDribble
9+
from src.behaviors.bhv_starter_shoot import BhvStarterShoot
10+
from src.utils.tools import Tools
711

812
class BhvStarterKickPlanner(IBehavior):
913
def __init__(self):
10-
pass
14+
'''self.starter_shoot = BhvStarterShoot()
15+
self.starter_clear_ball = BhvStarterClearBall()
16+
self.starter_dribble = BhvStarterDribble()
17+
self.starter_pass = BhvStarterPass()'''
1118

1219
def execute(self, agent: IAgent):
1320
agent.logger.debug("BhvStarterKickPlanner.execute")
1421
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
15-
assert isinstance(agent, SamplePlayerAgent)
16-
raise NotImplementedError("BhvStarterKickPlanner.execute not implemented")
22+
actions = []
23+
actions += [shoot] if (shoot := BhvStarterShoot.execute(agent)) is not None else []
24+
opps = Tools.OpponentsFromSelf(agent)
25+
nearest_opp = opps[0] if opps else None
26+
nearest_opp_dist = nearest_opp.dist_from_self if nearest_opp else 1000.0
27+
28+
if nearest_opp_dist < 10:
29+
actions += [passing] if (passing := BhvStarterPass.execute(agent)) is not None else []
30+
31+
actions += [dribble] if (dribble := BhvStarterDribble.execute(agent)) is not None else []
32+
33+
if nearest_opp_dist > 2.5:
34+
actions.append(PlayerAction(body_hold_ball=Body_HoldBall()))
35+
36+
actions.append(BhvStarterClearBall.execute(agent))
37+
38+
#Sending actions' queue
39+
for i in actions:
40+
if not i == []:
41+
agent.add_action(i)

0 commit comments

Comments
 (0)