Skip to content

Commit 5920a0c

Browse files
edit starter clearball, dribble, kick_planner, pass, shoot. add some setplay files: go_to_placed_ball, intention_wait_after_setplay, prepare_setplay_kick, setplay_freekick. add starter_strategy
1 parent 947ce4a commit 5920a0c

12 files changed

+387
-19
lines changed

idl/service.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ message Player {
172172
int32 ball_reach_steps = 28; // How many cycles the player needs to reach the ball.
173173
bool is_tackling = 29; // Whether the player is tackling or not.
174174
int32 type_id = 30; // The type identifier of the player.
175+
RpcVector2D inertia_final_point = 31;
175176
}
176177

177178
/**
@@ -220,6 +221,7 @@ message Self {
220221
CardType card = 39; // The card type of the agent. It can be NO_CARD, YELLOW, or RED.
221222
int32 catch_time = 40; // The time when the last catch command is performed.
222223
float effort = 41; // The effort of the agent. TODO more info
224+
float get_safety_dash_power = 42;
223225
}
224226

225227
/**
@@ -1296,6 +1298,8 @@ message bhv_doForceKick {}
12961298

12971299
message bhv_doHeardPassRecieve {}
12981300

1301+
message bhv_goalieFreeKick {}
1302+
12991303
message PlayerAction {
13001304
oneof action {
13011305
Dash dash = 1;
@@ -1366,6 +1370,7 @@ message PlayerAction {
13661370
bhv_doHeardPassRecieve bhv_do_heard_pass_recieve = 66;
13671371
HeliosBasicTackle helios_basic_tackle = 67;
13681372
Neck_OffensiveInterceptNeck neck_offensive_intercept_neck = 68;
1373+
bhv_goalieFreeKick bhv_goalie_free_kick = 69;
13691374
}
13701375
}
13711376

@@ -1668,6 +1673,7 @@ message ServerParam {
16681673
float goal_area_length = 224;
16691674
float center_circle_r = 225;
16701675
float goal_post_radius = 226;
1676+
float pitch_margin = 227;
16711677
}
16721678

16731679
message PlayerParam {

src/behaviors/bhv_starter_clearball.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
from pyrusgeom import vector_2d
77
from service_pb2 import *
88

9-
class BhvStarterClearBall(IBehavior):
9+
class BhvStarterClearBall():
1010

1111
def __init__(self):
1212
pass
1313

1414

15-
def execute(self, agent: IAgent):
15+
def execute(agent: IAgent):
1616
wm = agent.wm
1717
ball_pos = Vector2D(wm.ball.position.x, wm.ball.position.y)
1818
target = Vector2D(agent.server_params.pitch_half_length, 0.0)

src/behaviors/bhv_starter_dribble.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
from service_pb2 import *
77

88

9-
class BhvStarterDribble(IBehavior):
9+
class BhvStarterDribble():
1010

1111
def __init__(self):
1212
pass
1313

14-
def execute(self, agent: IAgent):
14+
def execute(agent: IAgent):
1515
wm = agent.wm
1616
ball_pos = Vector2D(wm.ball.position.x, wm.ball.position.y)
1717
dribble_angle = (Vector2D(52.5, 0) - ball_pos).th().degree()

src/behaviors/bhv_starter_kick_planner.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@
1111

1212
class BhvStarterKickPlanner(IBehavior):
1313
def __init__(self):
14-
self.starter_shoot = BhvStarterShoot()
14+
'''self.starter_shoot = BhvStarterShoot()
1515
self.starter_clear_ball = BhvStarterClearBall()
1616
self.starter_dribble = BhvStarterDribble()
17-
self.starter_pass = BhvStarterPass()
17+
self.starter_pass = BhvStarterPass()'''
1818

1919
def execute(self, agent: IAgent):
2020
agent.logger.debug("BhvStarterKickPlanner.execute")
2121
from src.sample_player_agent import SamplePlayerAgent # Local import to avoid circular import
2222
actions = []
23-
actions += [shoot] if (shoot := self.starter_shoot.execute(agent)) is not None else []
23+
actions += [shoot] if (shoot := BhvStarterShoot.execute(agent)) is not None else []
2424
opps = Tools.OpponentsFromSelf(agent)
2525
nearest_opp = opps[0] if opps else None
2626
nearest_opp_dist = nearest_opp.dist_from_self if nearest_opp else 1000.0
2727

2828
if nearest_opp_dist < 10:
29-
actions += [passing] if (passing := self.starter_pass.execute(agent)) is not None else []
29+
actions += [passing] if (passing := BhvStarterPass.execute(agent)) is not None else []
3030

31-
actions += [dribble] if (dribble := self.starter_dribble.execute(agent)) is not None else []
31+
actions += [dribble] if (dribble := BhvStarterDribble.execute(agent)) is not None else []
3232

3333
if nearest_opp_dist > 2.5:
3434
actions.append(PlayerAction(body_hold_ball=Body_HoldBall()))
3535

36-
actions.append(self.starter_clear_ball.execute(agent))
36+
actions.append(BhvStarterClearBall.execute(agent))
3737

3838
#Sending actions' queue
3939
for i in actions:

src/behaviors/bhv_starter_pass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
from service_pb2 import *
77

88

9-
class BhvStarterPass(IBehavior):
9+
class BhvStarterPass():
1010

1111
def __init__(self):
1212
pass
1313

14-
def execute(self, agent: IAgent) -> PlayerAction:
14+
def execute(agent: IAgent) -> PlayerAction:
1515

1616
wm = agent.wm
1717
target = []

src/behaviors/bhv_starter_shoot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66

77

8-
class BhvStarterShoot(IBehavior):
8+
class BhvStarterShoot():
99
def __init__(self):
1010
pass
1111

12-
def execute(self, agent: IAgent):
12+
def execute(agent: IAgent):
1313
wm = agent.wm
1414
ball_pos = Vector2D(wm.ball.position.x, wm.ball.position.y)
1515
ball_max_velocity = agent.server_params.ball_speed_max
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from src.interfaces.IAgent import IAgent
2+
from service_pb2 import *
3+
from pyrusgeom.vector_2d import Vector2D
4+
#from src.behaviors.starter_setplay.bhv_starter_setplay import BhvStarterSetPlay #TODO
5+
from src.utils.tools import Tools
6+
from src.utils.convertor import Convertor
7+
class BhvStarterGoToPlacedBall:
8+
9+
def __init__(self, angle: float):
10+
self.M_ball_place_angle = angle
11+
pass
12+
13+
def execute(self, agent: IAgent):
14+
actions = []
15+
from src.behaviors.starter_setplay.bhv_starter_setplay import BhvStarterSetPlay
16+
17+
dir_margin = 15.0
18+
sp = agent.server_params
19+
wm = agent.wm
20+
angle_diff = wm.ball.angle_from_self - self.M_ball_place_angle
21+
22+
if abs(angle_diff) < dir_margin and wm.ball.dist_from_self < (agent.player_types[wm.self.id].player_size + sp.ball_size + 0.08):
23+
# already reach
24+
return actions
25+
26+
# decide sub-target point
27+
ball_position = Convertor.convert_rpc_vector2d_to_vector2d(wm.ball.position)
28+
self_position = Convertor.convert_rpc_vector2d_to_vector2d(wm.self.position)
29+
sub_target = ball_position + Vector2D.polar2vector(2.0, self.M_ball_place_angle + 180.0)
30+
31+
dash_power = 20.0
32+
dash_speed = -1.0
33+
if wm.ball.dist_from_self > 2.0:
34+
dash_power = BhvStarterSetPlay.get_set_play_dash_power(agent)
35+
else:
36+
dash_speed = agent.player_types[wm.self.id].player_size
37+
dash_power = Tools.GetDashPowerToKeepSpeed(agent, dash_speed, wm.self.effort) #DEBUG NEEDED
38+
# it is necessary to go to sub target point
39+
if abs(angle_diff) > dir_margin:
40+
actions.append(PlayerAction(body_go_to_point=Body_GoToPoint(target_point=Convertor.convert_vector2d_to_rpc_vector2d(sub_target), distance_threshold=0.1, max_dash_power=50)))
41+
# dir diff is small. go to ball
42+
else:
43+
# body dir is not right
44+
if abs(wm.ball.angle_from_self - wm.self.body_direction) > 1.5:
45+
actions.append(PlayerAction(body_turn_to_ball=Body_TurnToBall(cycle=1)))
46+
# dash to ball
47+
else:
48+
actions.append(PlayerAction(dash=Dash(power=dash_power, relative_direction=0)))
49+
50+
return actions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from src.interfaces.IAgent import IAgent
2+
from service_pb2 import *
3+
4+
class BhvStarterIntentionWaitAfterSetPlayKick:
5+
6+
def __init__(self):
7+
pass
8+
9+
def finished(self, agent: IAgent) -> bool:
10+
wm = agent.wm
11+
12+
if wm.kickable_opponent_existance:
13+
return True
14+
15+
if not wm.self.is_kickable:
16+
return True
17+
18+
return False
19+
20+
def execute(self, agent: IAgent) -> bool:
21+
return [PlayerAction(bhv_body_neck_to_ball=Bhv_BodyNeckToBall())]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from src.interfaces.IAgent import IAgent
2+
from service_pb2 import *
3+
from pyrusgeom.angle_deg import AngleDeg
4+
class BhvStarterPrepareSetPlayKick:
5+
s_rest_wait_cycle = -1
6+
7+
def __init__(self, ball_place_angle: float, wait_cycle: float):
8+
self.M_ball_place_angle = ball_place_angle
9+
self.M_wait_cycle = wait_cycle
10+
11+
def execute(self, agent: IAgent) -> bool:
12+
actions = []
13+
from src.behaviors.starter_setplay.bhv_starter_go_to_placed_ball import BhvStarterGoToPlacedBall
14+
# Not reach the ball side
15+
actions += BhvStarterGoToPlacedBall(self.M_ball_place_angle).execute(agent)
16+
17+
# Reach to ball side
18+
if self.s_rest_wait_cycle < 0:
19+
self.s_rest_wait_cycle = self.M_wait_cycle
20+
21+
if self.s_rest_wait_cycle == 0:
22+
if (agent.wm.self.stamina < agent.server_params.stamina_max * 0.9 or agent.wm.self.seetime != agent.wm.cycle): #TODO
23+
self.s_rest_wait_cycle = 1
24+
25+
if self.s_rest_wait_cycle > 0:
26+
if agent.wm.game_mode_type == GameModeType.KickOff_:
27+
moment = AngleDeg(agent.server_params.visible_angle)
28+
actions.append(PlayerAction(turn=Turn(relative_direction=moment)))
29+
else:
30+
actions.append(PlayerAction(body_turn_to_ball=Body_TurnToBall(cycle=1)))
31+
32+
self.s_rest_wait_cycle -= 1
33+
34+
return actions
35+
36+
self.s_rest_wait_cycle = -1
37+
return []

0 commit comments

Comments
 (0)