Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nader performance #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
5 changes: 3 additions & 2 deletions base/bhv_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

if TYPE_CHECKING:
from lib.player.player_agent import PlayerAgent
from lib.player.object_player import PlayerObject

class Bhv_Block:
def execute(self, agent: 'PlayerAgent'):
Expand All @@ -23,14 +24,14 @@ def execute(self, agent: 'PlayerAgent'):
block_cycle = 1000
block_pos = Vector2D(0, 0)
for unum in range(1, 12):
tm = wm.our_player(unum)
tm: PlayerObject = wm.our_player(unum)
if tm is None:
continue
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)
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:
Expand Down
22 changes: 11 additions & 11 deletions base/generator_dribble.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ def generate_simple_dribble(self, wm: 'WorldModel'):
sp = SP.i()
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 @@ -113,8 +113,8 @@ 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()
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(
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 Down Expand Up @@ -194,7 +194,7 @@ 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)
Expand All @@ -218,7 +218,7 @@ def check_opponent(self, wm: 'WorldModel', ball_trap_pos: Vector2D, dribble_step

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 @@ -238,8 +238,8 @@ def check_opponent(self, wm: 'WorldModel', ball_trap_pos: Vector2D, dribble_step
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(),
opp._body,
opp._vel_r,
target_dist,
(ball_trap_pos - opp_pos).th(),
control_area,
Expand Down
Loading