Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions base/basic_tackle.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def execute(self, agent: 'PlayerAgent'):
wm = agent.world()

use_foul = False
tackle_prob = wm.self().tackle_probability()
tackle_prob = wm.self().tackle_probability

if wm.self().card() == Card.NO_CARD \
and (wm.ball().pos().x() > SP.our_penalty_area_line_x() + 0.5
or wm.ball().pos().abs_y() > SP.penalty_area_half_width() + 0.5) \
and tackle_prob < wm.self().foul_probability():
tackle_prob = wm.self().foul_probability()
if wm.self().card == Card.NO_CARD \
and (wm.ball().pos.x() > SP.our_penalty_area_line_x() + 0.5
or wm.ball().pos.abs_y() > SP.penalty_area_half_width() + 0.5) \
and tackle_prob < wm.self().foul_probability:
tackle_prob = wm.self().foul_probability
use_foul = True

if tackle_prob < self._min_prob:
Expand All @@ -44,7 +44,7 @@ def execute(self, agent: 'PlayerAgent'):

self_goal = False
if self_reach_point.x() < - SP.pitch_half_length():
ball_ray = Ray2D(wm.ball().pos(), wm.ball().vel().th())
ball_ray = Ray2D(wm.ball().pos, wm.ball().vel.th())
goal_line = Line2D(Vector2D(-SP.pitch_half_length(), +10),
Vector2D(-SP.pitch_half_length(), -10))

Expand All @@ -57,8 +57,8 @@ def execute(self, agent: 'PlayerAgent'):
or self_goal
or (opp_min < self_min - 3 and opp_min < mate_min - 3)
or (self_min >= 5
and wm.ball().pos().dist2(SP.their_team_goal_pos()) < 10 **2
and ((SP.their_team_goal_pos() - wm.self().pos()).th() - wm.self().body()).abs() < 45.)):
and wm.ball().pos.dist2(SP.their_team_goal_pos()) < 10 **2
and ((SP.their_team_goal_pos() - wm.self().pos).th() - wm.self().body).abs() < 45.)):

return False

Expand All @@ -69,10 +69,10 @@ def executeV14(self, agent: 'PlayerAgent', use_foul: bool):

result = TackleGenerator.instance().best_result(wm)

ball_next = wm.ball().pos() + result._ball_vel
ball_next = wm.ball().pos + result._ball_vel

log.debug_client().add_message(f"Basic{'Foul' if use_foul else 'Tackle'}{result._tackle_angle.degree()}")
tackle_dir = (result._tackle_angle - wm.self().body()).degree()
tackle_dir = (result._tackle_angle - wm.self().body).degree()

agent.do_tackle(tackle_dir, use_foul)
agent.set_neck_action(NeckTurnToPoint(ball_next))
Expand Down
6 changes: 3 additions & 3 deletions base/bhv_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def execute(self, agent: 'PlayerAgent'):
tm = wm.our_player(unum)
if tm is None:
continue
if tm.unum() < 1:
if tm.unum < 1:
continue
for c in range(1, 40):
dribble_pos = ball_pos + Vector2D.polar2vector(c * dribble_speed_etimate, dribble_angle_estimate)
turn_cycle = Tools.predict_player_turn_cycle(tm.player_type(), tm.body(), tm.vel().r(), tm.pos().dist(dribble_pos), (dribble_pos - tm.pos()).th(), 0.2, False)
tm_cycle = tm.player_type().cycles_to_reach_distance(tm.inertia_point(opp_min).dist(dribble_pos)) + turn_cycle
turn_cycle = Tools.predict_player_turn_cycle(tm.player_type, tm.body, tm.vel.r(), tm.pos.dist(dribble_pos), (dribble_pos - tm.pos).th(), 0.2, False)
tm_cycle = tm.player_type.cycles_to_reach_distance(tm.inertia_point(opp_min).dist(dribble_pos)) + turn_cycle
if tm_cycle <= opp_min + c:
if tm_cycle < block_cycle:
block_cycle = tm_cycle
Expand Down
4 changes: 2 additions & 2 deletions base/bhv_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def execute(self, agent: 'PlayerAgent'):
agent.set_neck_action(NeckTurnToBall())
return True
st = StrategyFormation().i()
target = st.get_pos(agent.world().self().unum())
target = st.get_pos(agent.world().self().unum)

log.debug_client().set_target(target)
log.debug_client().add_message('bhv_move')

dash_power, self._in_recovery_mode = get_normal_dash_power(wm, self._in_recovery_mode)
dist_thr = wm.ball().dist_from_self() * 0.1
dist_thr = wm.ball().dist_from_self * 0.1

if dist_thr < 1.0:
dist_thr = 1.0
Expand Down
10 changes: 5 additions & 5 deletions base/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ def get_decision(agent: 'PlayerAgent'):
st = StrategyFormation().i()
st.update(wm)

if wm.self().goalie():
if wm.self().goalie:
if goalie_decision.decision(agent):
return True

if wm.game_mode().type() != GameModeType.PlayOn:
if Bhv_SetPlay().execute(agent):
return True

log.sw_log().team().add_text(f'is kickable? dist {wm.ball().dist_from_self()} '
f'ka {wm.self().player_type().kickable_area()} '
f'seen pos count {wm.ball().seen_pos_count()} '
f'is? {wm.self()._kickable}')
log.sw_log().team().add_text(f'is kickable? dist {wm.ball().dist_from_self} '
f'ka {wm.self().player_type.kickable_area()} '
f'seen pos count {wm.ball().seen_pos_count} '
f'is? {wm.self().is_kickable()}')
if wm.self().is_kickable():
return BhvKick().execute(agent)
if BhvMove().execute(agent):
Expand Down
8 changes: 4 additions & 4 deletions base/generator_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self):
def calculate_min_opp_dist(self, wm: 'WorldModel' = None):
if wm is None:
return 0.0
return min([opp.pos().dist(self.target_ball_pos) for opp in wm.opponents() if opp is not None and opp.unum() > 0])
return min([opp.pos.dist(self.target_ball_pos) for opp in wm.opponents() if opp is not None and opp.unum > 0])

def evaluate(self, wm: 'WorldModel' = None):
self.min_opp_dist = self.calculate_min_opp_dist(wm)
Expand Down Expand Up @@ -105,10 +105,10 @@ def __init__(self):
def can_opponent_cut_ball(self, wm: 'WorldModel', ball_pos, cycle):
for unum in range(1, 12):
opp: 'PlayerObject' = wm.their_player(unum)
if opp.unum() == 0:
if opp.unum == 0:
continue
opp_cycle = opp.pos().dist(ball_pos) - opp.player_type().kickable_area()
opp_cycle /= opp.player_type().real_speed_max()
opp_cycle = opp.pos.dist(ball_pos) - opp.player_type.kickable_area()
opp_cycle /= opp.player_type.real_speed_max()
if opp_cycle < cycle:
return True
return False
12 changes: 6 additions & 6 deletions base/generator_clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def generator(self, wm: 'WorldModel'):
def add_to_candidate(self, wm: 'WorldModel', ball_pos: Vector2D):
action = KickAction()
action.target_ball_pos = ball_pos
action.start_ball_pos = wm.ball().pos()
action.start_ball_pos = wm.ball().pos.copy()
action.start_ball_speed = 2.5
action.type = KickActionType.Clear
action.index = self.index
Expand Down Expand Up @@ -58,7 +58,7 @@ def generate_clear_ball(self, wm: 'WorldModel'):
angle_step = 360.0 / angle_div

for a in range(angle_div):
ball_pos = wm.ball().pos()
ball_pos = wm.ball().pos.copy()
angle = AngleDeg(a * angle_step)
speed = 2.5
log.sw_log().clear().add_text(f'========= a:{a} speed:{speed} angle:{angle} ball:{ball_pos}')
Expand All @@ -76,12 +76,12 @@ def generate_clear_ball(self, wm: 'WorldModel'):
for opp in wm.opponents():
if not opp:
continue
if opp.unum() <= 0:
if opp.unum <= 0:
continue
opp_cycle = opp.pos().dist(ball_pos) / opp.player_type().real_speed_max() - opp.player_type().kickable_area()
opp_cycle -= min(0, opp.pos_count())
opp_cycle = opp.pos.dist(ball_pos) / opp.player_type.real_speed_max() - opp.player_type.kickable_area()
opp_cycle -= min(0, opp.pos_count)
if opp_cycle <= c:
receiver_opp = opp.unum()
receiver_opp = opp.unum
break
if receiver_opp != 0:
break
Expand Down
54 changes: 27 additions & 27 deletions base/generator_dribble.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ def generate_simple_dribble(self, wm: 'WorldModel'):
angle_step = 360.0 / angle_div

sp = SP.i()
ptype = wm.self().player_type()
ptype = wm.self().player_type

my_first_speed = wm.self().vel().r()
my_first_speed = wm.self().vel.r()

for a in range(angle_div):
dash_angle = wm.self().body() + (angle_step * a)
dash_angle = wm.self().body + (angle_step * a)

if wm.self().pos().x() < 16.0 and dash_angle.abs() > 100.0:
if wm.self().pos.x() < 16.0 and dash_angle.abs() > 100.0:
if debug_dribble:
log.sw_log().dribble().add_text( '#dash angle:{} cancel is not safe1'.format(dash_angle))
continue

if wm.self().pos().x() < -36.0 and wm.self().pos().abs_y() < 20.0 and dash_angle.abs() > 45.0:
if wm.self().pos.x() < -36.0 and wm.self().pos.abs_y() < 20.0 and dash_angle.abs() > 45.0:
if debug_dribble:
log.sw_log().dribble().add_text( '#dash angle:{} cancel is not safe2'.format(dash_angle))
continue
Expand Down Expand Up @@ -93,7 +93,7 @@ def simulate_kick_turns_dashes(self, wm: 'WorldModel', dash_angle, n_turn):
if debug_dribble:
log.sw_log().dribble().add_text( '##self_cache:{}'.format(self_cache))
sp = SP.i()
ptype = wm.self().player_type()
ptype = wm.self().player_type

# trap_rel = Vector2D.polar2vector(ptype.playerSize() + ptype.kickableMargin() * 0.2 + SP.ball_size(), dash_angle)
trap_rel = Vector2D.polar2vector(ptype.player_size() + ptype.kickable_margin() * 0.2 + 0, dash_angle)
Expand All @@ -113,9 +113,9 @@ def simulate_kick_turns_dashes(self, wm: 'WorldModel', dash_angle, n_turn):
continue

term = (1.0 - pow(sp.ball_decay(), 1 + n_turn + n_dash ) ) / (1.0 - sp.ball_decay())
first_vel: Vector2D = (ball_trap_pos - wm.ball().pos()) / term
kick_accel: Vector2D = first_vel - wm.ball().vel()
kick_power = kick_accel.r() / wm.self().kick_rate()
first_vel: Vector2D = (ball_trap_pos - wm.ball().pos) / term
kick_accel: Vector2D = first_vel - wm.ball().vel
kick_power = kick_accel.r() / wm.self().kick_rate

if kick_power > sp.max_power() or kick_accel.r2() > pow(sp.ball_accel_max(), 2) or first_vel.r2() > pow(
sp.ball_speed_max(), 2):
Expand All @@ -126,7 +126,7 @@ def simulate_kick_turns_dashes(self, wm: 'WorldModel', dash_angle, n_turn):
self.debug_list.append((self.index, ball_trap_pos, False))
continue

if (wm.ball().pos() + first_vel).dist2(self_cache[0]) < pow(ptype.player_size() + sp.ball_size() + 0.1, 2):
if (wm.ball().pos + first_vel).dist2(self_cache[0]) < pow(ptype.player_size() + sp.ball_size() + 0.1, 2):
if debug_dribble:
log.sw_log().dribble().add_text(
'#index:{} target:{} in body, power:{}, accel:{}, vel:{}'.format(
Expand All @@ -137,9 +137,9 @@ def simulate_kick_turns_dashes(self, wm: 'WorldModel', dash_angle, n_turn):
if self.check_opponent(wm, ball_trap_pos, 1 + n_turn + n_dash):
candidate = KickAction()
candidate.type = KickActionType.Dribble
candidate.start_ball_pos = wm.ball().pos()
candidate.start_ball_pos = wm.ball().pos.copy()
candidate.target_ball_pos = ball_trap_pos
candidate.target_unum = wm.self().unum()
candidate.target_unum = wm.self().unum
candidate.start_ball_speed = first_vel.r()
candidate.index = self.index
candidate.evaluate(wm)
Expand All @@ -158,14 +158,14 @@ def simulate_kick_turns_dashes(self, wm: 'WorldModel', dash_angle, n_turn):

def create_self_cache(self, wm: 'WorldModel', dash_angle, n_turn, n_dash, self_cache):
sp = SP.i()
ptype = wm.self().player_type()
ptype = wm.self().player_type

self_cache.clear()

stamina_model = wm.self().stamina_model()
stamina_model = wm.self().stamina_model.copy()

my_pos = wm.self().pos()
my_vel = wm.self().vel()
my_pos = wm.self().pos.copy()
my_vel = wm.self().vel.copy()

my_pos += my_vel
my_vel *= ptype.player_decay()
Expand Down Expand Up @@ -194,31 +194,31 @@ def create_self_cache(self, wm: 'WorldModel', dash_angle, n_turn, n_dash, self_c

def check_opponent(self, wm: 'WorldModel', ball_trap_pos: Vector2D, dribble_step: int):
sp = SP.i()
ball_move_angle:AngleDeg = (ball_trap_pos - wm.ball().pos()).th()
ball_move_angle:AngleDeg = (ball_trap_pos - wm.ball().pos).th()

for o in range(12):
opp: 'PlayerObject' = wm.their_player(o)
if opp is None or opp.unum() == 0:
if opp is None or opp.unum == 0:
if debug_dribble:
log.sw_log().dribble().add_text( "###OPP {} is ghost".format(o))
continue

if opp.dist_from_self() > 20.0:
if opp.dist_from_self > 20.0:
if debug_dribble:
log.sw_log().dribble().add_text( "###OPP {} is far".format(o))
continue

ptype = opp.player_type()
ptype = opp.player_type

control_area = (sp._catchable_area
if opp.goalie()
if opp.goalie
and ball_trap_pos.x() > sp.their_penalty_area_line_x()
and ball_trap_pos.abs_y() < sp.penalty_area_half_width()
else ptype.kickable_area())

opp_pos = opp.inertia_point( dribble_step )

ball_to_opp_rel = (opp.pos() - wm.ball().pos()).rotated_vector(-ball_move_angle)
ball_to_opp_rel = (opp.pos - wm.ball().pos).rotated_vector(-ball_move_angle)

if ball_to_opp_rel.x() < -4.0:
if debug_dribble:
Expand All @@ -237,9 +237,9 @@ def check_opponent(self, wm: 'WorldModel', ball_trap_pos: Vector2D, dribble_step
dash_dist -= 0.2
n_dash = ptype.cycles_to_reach_distance(dash_dist)

n_turn = 1 if opp.body_count() > 1 else Tools.predict_player_turn_cycle(ptype,
opp.body(),
opp.vel().r(),
n_turn = 1 if opp.body_count > 1 else Tools.predict_player_turn_cycle(ptype,
opp.body,
opp.vel.r(),
target_dist,
(ball_trap_pos - opp_pos).th(),
control_area,
Expand All @@ -258,9 +258,9 @@ def check_opponent(self, wm: 'WorldModel', ball_trap_pos: Vector2D, dribble_step
bonus_step = -5

if ball_to_opp_rel.x() > 0.5:
bonus_step += smath.bound(0, opp.pos_count(), 8)
bonus_step += smath.bound(0, opp.pos_count, 8)
else:
bonus_step += smath.bound(0, opp.pos_count(), 4)
bonus_step += smath.bound(0, opp.pos_count, 4)

if n_step - bonus_step <= dribble_step:
if debug_dribble:
Expand Down
Loading