Skip to content

Commit 264ca49

Browse files
add more setplay files
1 parent 5920a0c commit 264ca49

File tree

3 files changed

+659
-0
lines changed

3 files changed

+659
-0
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
from src.interfaces.IAgent import IAgent
2+
from service_pb2 import *
3+
from pyrusgeom.vector_2d import Vector2D
4+
#from src.setplay.BhvSetPlay import BhvSetPlay
5+
from src.behaviors.bhv_starter_clearball import BhvStarterClearBall
6+
from src.utils.tools import Tools
7+
from src.behaviors.bhv_starter_kick_planner import BhvStarterKickPlanner
8+
from src.behaviors.bhv_starter_pass import BhvStarterPass
9+
from src.strategy.starter_strategy import StarterStrategy
10+
from src.behaviors.bhv_starter_clearball import BhvStarterClearBall
11+
from src.utils.convertor import Convertor
12+
13+
class BhvStarterSetPlayGoalKick:
14+
def __init__():
15+
pass
16+
17+
def execute(agent:IAgent):
18+
from src.behaviors.starter_setplay.bhv_starter_setplay import BhvStarterSetPlay
19+
if BhvStarterSetPlay.is_kicker(agent):
20+
return BhvStarterSetPlayGoalKick.do_kick(agent)
21+
else:
22+
return BhvStarterSetPlayGoalKick.do_move(agent)
23+
24+
def do_kick(agent: IAgent):
25+
from src.behaviors.starter_setplay.bhv_starter_go_to_placed_ball import BhvStarterGoToPlacedBall
26+
27+
actions = []
28+
actions += BhvStarterSetPlayGoalKick.do_second_kick(agent)
29+
30+
actions += BhvStarterGoToPlacedBall(0.0).execute(agent)
31+
32+
wait = BhvStarterSetPlayGoalKick.do_kick_wait(agent)
33+
if wait != []:
34+
actions += wait
35+
return actions
36+
37+
actions += BhvStarterSetPlayGoalKick.do_pass(agent)
38+
39+
actions += BhvStarterSetPlayGoalKick.do_kick_to_far_side(agent)
40+
41+
wm = agent.wm
42+
real_set_play_count = wm.cycle - agent.wm.last_set_play_start_time
43+
if real_set_play_count <= agent.server_params.drop_ball_time - 10:
44+
actions.append(PlayerAction(body_turn_to_ball=Body_TurnToBall(cycle=1)))
45+
return actions
46+
actions.append(BhvStarterClearBall.execute(agent))
47+
return actions
48+
49+
def do_second_kick(agent:IAgent):
50+
wm = agent.wm
51+
actions = []
52+
ball_position = Vector2D(wm.ball.position.x, wm.ball.position.y)
53+
ball_velocity = Vector2D(wm.ball.velocity.x, wm.ball.velocity.y)
54+
if wm.ball.position.x < -agent.server_params.pitch_half_length + agent.server_params.goal_area_length + 1.0 and abs(wm.ball.position.y) < agent.server_params.goal_width * 0.5 + 1.0:
55+
return []
56+
57+
if wm.self.is_kickable:
58+
actions += BhvStarterSetPlayGoalKick.do_pass(agent)
59+
actions += BhvStarterClearBall.execute(agent)
60+
61+
actions += BhvStarterSetPlayGoalKick.do_intercept(agent)
62+
63+
ball_final = Tools.BallInertiaFinalPoint(ball_position, ball_velocity, agent.server_params.ball_decay)
64+
65+
actions.append(PlayerAction(body_go_to_point=Body_GoToPoint(target_point=Convertor.convert_vector2d_to_rpc_vector2d(ball_final), distance_threshold=2.0, max_dash_power=agent.server_params.max_dash_power)))
66+
67+
actions.append(PlayerAction(body_turn_to_point=Body_TurnToPoint(target_point=RpcVector2D(0, 0), cycle=2)))
68+
69+
return actions
70+
71+
def do_kick_wait(agent:IAgent):
72+
wm = agent.wm
73+
actions = []
74+
real_set_play_count = wm.cycle - wm.last_set_play_start_time
75+
76+
if real_set_play_count >= agent.server_params.drop_ball_time - 10:
77+
return []
78+
from src.behaviors.starter_setplay.bhv_starter_setplay import BhvStarterSetPlay
79+
if BhvStarterSetPlay.is_delaying_tactics_situation(agent):
80+
actions.append(PlayerAction(body_turn_to_ball=Body_TurnToBall(cycle=1)))
81+
return actions
82+
83+
if abs(wm.ball.angle_from_self - wm.self.body_direction) > 3.0:
84+
actions.append(PlayerAction(body_turn_to_ball=Body_TurnToBall(cycle=1)))
85+
return actions
86+
87+
if wm.set_play_count <= 6:
88+
actions.append(PlayerAction(body_turn_to_ball=Body_TurnToBall(cycle=1)))
89+
return actions
90+
91+
if wm.set_play_count <= 30 and len(Tools.TeammatesFromSelf(agent)) == 0:
92+
actions.append(PlayerAction(body_turn_to_ball=Body_TurnToBall(cycle=1)))
93+
return actions
94+
95+
if wm.set_play_count >= 15 and wm.see_time == wm.cycle and wm.self.stamina > agent.server_params.stamina_max:
96+
return []
97+
98+
if wm.set_play_count <= 3 or wm.see_time != wm.cycle or wm.self.stamina < agent.server_params.stamina_max * 0.9:
99+
actions.append(PlayerAction(body_turn_to_ball=Body_TurnToBall(cycle=1)))
100+
return actions
101+
102+
return []
103+
104+
def do_pass(agent:IAgent):
105+
return [BhvStarterPass.execute(agent)]
106+
107+
def do_intercept(agent:IAgent):
108+
wm = agent.wm
109+
actions = []
110+
111+
if wm.ball.position.x < -agent.server_params.pitch_half_length + agent.server_params.goal_area_length + 1.0 and abs(wm.ball.position.y) < agent.server_params.goal_area_width * 0.5 + 1.0:
112+
return []
113+
114+
if wm.self.is_kickable:
115+
return []
116+
117+
self_min = wm.intercept_table.self_reach_steps
118+
mate_min = wm.intercept_table.first_teammate_reach_steps
119+
if self_min > mate_min:
120+
return []
121+
122+
ball_position = Vector2D(wm.ball.position.x, wm.ball.position.y)
123+
ball_velocity = Vector2D(wm.ball.velocity.x, wm.ball.velocity.y)
124+
trap_pos = Tools.inertia_point(ball_position, ball_velocity, self_min, agent.server_params.ball_decay)
125+
if (trap_pos.x() > agent.server_params.our_penalty_area_line_x - 8.0 and abs(trap_pos.y()) > agent.server_params.penalty_area_half_width - 5.0) or ball_velocity.r2() < 0.25:
126+
actions.append(PlayerAction(body_intercept=Body_Intercept()))
127+
128+
return actions
129+
130+
def do_move(agent:IAgent):
131+
actions = []
132+
actions += BhvStarterSetPlayGoalKick.do_intercept(agent)
133+
from src.behaviors.starter_setplay.bhv_starter_setplay import BhvStarterSetPlay
134+
wm = agent.wm
135+
ball_position = Vector2D(wm.ball.position.x, wm.ball.position.y)
136+
dash_power = BhvStarterSetPlay.get_set_play_dash_power(agent)
137+
dist_thr = max(wm.ball.dist_from_self * 0.07, 1.0)
138+
139+
target_rpc = StarterStrategy.get_position(agent, wm.self.uniform_number)
140+
target_point = Vector2D(target_rpc.x, target_rpc.y)
141+
target_point.set_y(target_point.y() + wm.ball.position.y * 0.5)
142+
143+
if abs(target_point.y()) > agent.server_params.pitch_half_width - 1.0:
144+
target_point.set_y((target_point.y() / abs(target_point.y())) * (agent.server_params.pitch_half_width - 1.0))
145+
146+
if wm.self.stamina > agent.server_params.stamina_max * 0.9:
147+
148+
nearest_opp = Tools.GetOpponentNearestToSelf(agent)
149+
if nearest_opp and nearest_opp.dist_from_self < 3.0:
150+
add_vec = ball_position - target_point
151+
add_vec.set_length(3.0)
152+
153+
time_val = wm.cycle % 60
154+
if time_val < 20:
155+
pass
156+
elif time_val < 40:
157+
target_point += add_vec.rotated_vector(90.0)
158+
else:
159+
target_point += add_vec.rotated_vector(-90.0)
160+
161+
target_point.set_x(min(max(-agent.server_params.pitch_half_length, target_point.x()), agent.server_params.pitch_half_length))
162+
target_point.set_y(min(max(-agent.server_params.pitch_half_width, target_point.y()), agent.server_params.pitch_half_width))
163+
164+
actions.append(PlayerAction(body_go_to_point=Body_GoToPoint(target_point=Convertor.convert_vector2d_to_rpc_vector2d(target_point), distance_threshold=dist_thr, max_dash_power=dash_power)))
165+
actions.append(PlayerAction(body_turn_to_ball=Body_TurnToBall(cycle=1)))
166+
167+
self_position = Vector2D(wm.self.position.x, wm.self.position.y)
168+
if (self_position.dist(target_point) > ball_position.dist(target_point) * 0.2 + 6.0 or wm.self.stamina < agent.server_params.stamina_max * 0.7):
169+
if not wm.self.stamina_capacity == 0: #TODO
170+
pass
171+
172+
return actions
173+
174+
def do_kick_to_far_side(agent:IAgent):
175+
wm = agent.wm
176+
actions = []
177+
target_point = Vector2D(agent.server_params.our_penalty_area_line_x - 5.0, agent.server_params.penalty_area_half_width)
178+
if wm.ball.position.y > 0.0:
179+
target_point.set_y( target_point.y() * -1.0)
180+
ball_position = Vector2D(wm.ball.position.x, wm.ball.position.y)
181+
ball_move_dist = ball_position.dist(target_point)
182+
ball_first_speed = Tools.calc_first_term_geom_series_last(0.7, ball_move_dist, agent.server_params.ball_decay)
183+
ball_first_speed = min(agent.server_params.ball_speed_max, ball_first_speed)
184+
ball_first_speed = min(wm.self.kick_rate * agent.server_params.max_power, ball_first_speed)
185+
186+
accel = target_point - ball_position
187+
accel.set_length(ball_first_speed)
188+
189+
kick_power = min(agent.server_params.max_power, accel.r() / wm.self.kick_rate)
190+
kick_angle = accel.th()
191+
actions.append(PlayerAction(kick=Kick(power=kick_power, relative_direction=kick_angle.degree() - wm.self.body_direction)))
192+
return actions

0 commit comments

Comments
 (0)