diff --git a/base/bhv_block.py b/base/bhv_block.py index e1e1a02a..170fb88f 100644 --- a/base/bhv_block.py +++ b/base/bhv_block.py @@ -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'): @@ -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: diff --git a/base/generator_dribble.py b/base/generator_dribble.py index 71527811..cc8addf3 100644 --- a/base/generator_dribble.py +++ b/base/generator_dribble.py @@ -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 @@ -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( @@ -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( @@ -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) @@ -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: @@ -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, diff --git a/base/generator_pass.py b/base/generator_pass.py index ece617c5..8abc9912 100644 --- a/base/generator_pass.py +++ b/base/generator_pass.py @@ -14,7 +14,7 @@ from lib.player.world_model import WorldModel from lib.player.object_player import PlayerObject -debug_pass = True +debug_pass = False max_pass_time = 0 @@ -71,15 +71,15 @@ def update_receivers(self, wm: 'WorldModel'): if tm.is_tackling(): log.sw_log().pass_().add_text(f'-----<<< TM is tackling') continue - if tm.pos().x() > wm.offside_line_x(): + if tm._pos.x() > wm.offside_line_x(): log.sw_log().pass_().add_text(f'-----<<< TM is in offside {tm.pos().x()} > {wm.offside_line_x()}') continue - if tm.goalie() and tm.pos().x() < sp.our_penalty_area_line_x() + 15: + if tm.goalie() and tm._pos.x() < sp.our_penalty_area_line_x() + 15: log.sw_log().pass_().add_text(f'-----<<< TM is goalie and danger {tm.pos().x()} < {sp.our_penalty_area_line_x() + 15}') continue log.sw_log().pass_().add_text(f'--->>>>> TM {tm.unum()} is added') self.receivers.append(tm) - self.receivers = sorted(self.receivers, key=lambda p: p.pos().x(), reverse=True) + self.receivers = sorted(self.receivers, key=lambda p: p._pos.x(), reverse=True) def generate_direct_pass(self, wm: 'WorldModel', receiver: 'PlayerObject'): sp = SP.i() @@ -87,15 +87,15 @@ def generate_direct_pass(self, wm: 'WorldModel', receiver: 'PlayerObject'): max_direct_pass_dist = 0.8 * smath.inertia_final_distance(sp.ball_speed_max(), sp.ball_decay()) max_receive_ball_speed = sp.ball_speed_max() * pow(sp.ball_decay(), min_receive_step) min_direct_pass_dist = receiver.player_type().kickable_area() * 2.2 - if receiver.pos().x() > sp.pitch_half_length() - 1.5 \ - or receiver.pos().x() < -sp.pitch_half_length() + 5.0 \ - or receiver.pos().abs_y() > sp.pitch_half_width() - 1.5: + if receiver._pos.x() > sp.pitch_half_length() - 1.5 \ + or receiver._pos.x() < -sp.pitch_half_length() + 5.0 \ + or receiver._pos.abs_y() > sp.pitch_half_width() - 1.5: if debug_pass: log.sw_log().pass_().add_text( '#DPass to {} {}, out of field'.format(receiver.unum(), receiver.pos())) return # TODO sp.ourTeamGoalPos() - if receiver.pos().x() < wm.ball().pos().x() + 1.0 \ - and receiver.pos().dist2(Vector2D(-52.5, 0)) < pow(18.0, 2): + if receiver._pos.x() < wm.ball()._pos.x() + 1.0 \ + and receiver._pos.dist2(Vector2D(-52.5, 0)) < pow(18.0, 2): if debug_pass: log.sw_log().pass_().add_text( '#DPass to {} {}, danger near goal'.format(receiver.unum(), receiver.pos())) return @@ -108,8 +108,8 @@ def generate_direct_pass(self, wm: 'WorldModel', receiver: 'PlayerObject'): # TODO SP.defaultRealSpeedMax() min_ball_speed = 1.0 - receive_point = ptype.inertiaFinalPoint(receiver.pos(), receiver.vel()) - ball_move_dist = wm.ball().pos().dist(receive_point) + receive_point = ptype.inertiaFinalPoint(receiver._pos, receiver._vel) + ball_move_dist = wm.ball()._pos.dist(receive_point) if ball_move_dist < min_direct_pass_dist or max_direct_pass_dist < ball_move_dist: if debug_pass: @@ -128,13 +128,13 @@ def generate_direct_pass(self, wm: 'WorldModel', receiver: 'PlayerObject'): sp.max_dash_power() * ptype.dash_power_rate() * ptype.effort_max()) * 1.8) min_receive_ball_speed = ptype.real_speed_max() - ball_move_angle = (receive_point - wm.ball().pos()).th() + ball_move_angle = (receive_point - wm.ball()._pos).th() min_ball_step = sp.ball_move_step(sp.ball_speed_max(), ball_move_dist) # TODO Penalty step start_step = max(max(min_receive_step, min_ball_step), 0) max_step = start_step + 2 - log.sw_log().pass_().add_text( '#DPass to {} {}'.format(receiver.unum(), receiver.pos())) + log.sw_log().pass_().add_text( '#DPass to {} {}'.format(receiver.unum(), receiver._pos)) self.create_pass(wm, receiver, receive_point, start_step, max_step, min_ball_speed, max_ball_speed, min_receive_ball_speed, @@ -151,7 +151,7 @@ def generate_lead_pass(self, wm: 'WorldModel', receiver): max_receive_ball_speed = sp.ball_speed_max() * pow(sp.ball_decay(), min_receive_step) max_player_distance = 35 - if receiver.pos().dist(wm.ball().pos()) > max_player_distance: + if receiver._pos.dist(wm.ball()._pos) > max_player_distance: if debug_pass: log.sw_log().pass_().add_text( '#####LPass to {} {}, player is far'.format(receiver.unum(), receiver.pos())) return @@ -173,7 +173,7 @@ def generate_lead_pass(self, wm: 'WorldModel', receiver): our_goal = Vector2D(-52.5, 0) - angle_from_ball = (receiver.pos() - wm.ball().pos()).th() + angle_from_ball = (receiver._pos - wm.ball()._pos).th() for d in range(1, dist_divs + 1): player_move_dist = dist_step * d a_step = 2 if player_move_dist * 2.0 * math.pi / abgle_divs < 0.6 else 1 @@ -182,8 +182,8 @@ def generate_lead_pass(self, wm: 'WorldModel', receiver): receive_point = receiver.inertia_point(1) + Vector2D.from_polar(player_move_dist, angle) move_dist_penalty_step = 0 - ball_move_line = Line2D(wm.ball().pos(), receive_point) - player_line_dist = ball_move_line.dist(receiver.pos()) + ball_move_line = Line2D(wm.ball()._pos, receive_point) + player_line_dist = ball_move_line.dist(receiver._pos) move_dist_penalty_step = int(player_line_dist * 0.3) if receive_point.x() > sp.pitch_half_length() - 3.0 \ or receive_point.x() < -sp.pitch_half_length() + 5.0 \ @@ -192,7 +192,7 @@ def generate_lead_pass(self, wm: 'WorldModel', receiver): log.sw_log().pass_().add_text( '#####LPass to {} {}, out of field'.format(receiver.unum(), receive_point)) continue - if receive_point.x() < wm.ball().pos().x() \ + if receive_point.x() < wm.ball()._pos.x() \ and receive_point.dist2(our_goal) < our_goal_dist_thr2: if debug_pass: log.sw_log().pass_().add_text( '#####LPass to {} {}, pass is danger'.format(receiver.unum(), receive_point)) @@ -205,7 +205,7 @@ def generate_lead_pass(self, wm: 'WorldModel', receiver): log.sw_log().pass_().add_text( '#####LPass to {} {}, in penalty area'.format(receiver.unum(), receive_point)) return - ball_move_dist = wm.ball().pos().dist(receive_point) + ball_move_dist = wm.ball()._pos.dist(receive_point) if ball_move_dist < min_leading_pass_dist or max_leading_pass_dist < ball_move_dist: if debug_pass: @@ -222,7 +222,7 @@ def generate_lead_pass(self, wm: 'WorldModel', receiver): receiver_step = self.predict_receiver_reach_step(receiver, receive_point, True, 'L') + move_dist_penalty_step - ball_move_angle = (receive_point - wm.ball().pos()).th() + ball_move_angle = (receive_point - wm.ball()._pos).th() min_ball_step = sp.ball_move_step(sp.ball_speed_max(), ball_move_dist) @@ -250,23 +250,23 @@ def generate_through_pass(self, wm: 'WorldModel', receiver: 'PlayerObject'): max_receive_ball_speed = sp.ball_speed_max() * pow(sp.ball_decay(), min_receive_step) max_player_distance = 35 - if receiver.pos().dist(wm.ball().pos()) > max_player_distance: + if receiver._pos.dist(wm.ball()._pos) > max_player_distance: if debug_pass: log.sw_log().pass_().add_text('#####TPass to {} {}, player is far'.format(receiver.unum(), receiver.pos())) return - if receiver.pos().x() < teammate_min_x: + if receiver._pos.x() < teammate_min_x: if debug_pass: log.sw_log().pass_().add_text('#####TPass to {} {}, player is far'.format(receiver.unum(), receiver.pos())) return - if receiver.pos().x() < wm.offside_line_x() - 5.0: + if receiver._pos.x() < wm.offside_line_x() - 5.0: if debug_pass: log.sw_log().pass_().add_text('#####TPass to {} {}, player is not close to offside line'.format(receiver.unum(), receiver.pos())) return - if receiver.pos().x() > wm.offside_line_x() - 0.5: + if receiver._pos.x() > wm.offside_line_x() - 0.5: if debug_pass: log.sw_log().pass_().add_text('#####TPass to {} {}, player is in offside'.format(receiver.unum(), receiver.pos())) return - if wm.ball().pos().x() < -10.0 or wm.ball().pos().x() > 30.0: + if wm.ball()._pos.x() < -10.0 or wm.ball()._pos.x() > 30.0: if debug_pass: log.sw_log().pass_().add_text('#####TPass to {} {}, ball x is low or high'.format(receiver.unum(), receiver.pos())) return @@ -289,15 +289,15 @@ def generate_through_pass(self, wm: 'WorldModel', receiver: 'PlayerObject'): our_goal = Vector2D(-52.5, 0) - angle_from_ball = (receiver.pos() - wm.ball().pos()).th() + angle_from_ball = (receiver._pos - wm.ball()._pos).th() for d in range(5, dist_divs + 1): player_move_dist = dist_step * d for a in range(min_angle, max_angle + 1, angle_step): receive_point = receiver.inertia_point(1) + Vector2D.from_polar(player_move_dist, a) move_dist_penalty_step = 0 - ball_move_line = Line2D(wm.ball().pos(), receive_point) - player_line_dist = ball_move_line.dist(receiver.pos()) + ball_move_line = Line2D(wm.ball()._pos, receive_point) + player_line_dist = ball_move_line.dist(receiver._pos) move_dist_penalty_step = int(player_line_dist * 0.3) if receive_point.x() > sp.pitch_half_length() - 3.0 \ or receive_point.x() < -sp.pitch_half_length() + 5.0 \ @@ -311,7 +311,7 @@ def generate_through_pass(self, wm: 'WorldModel', receiver: 'PlayerObject'): log.sw_log().pass_().add_text('#####TPass to {} {}, pass is danger'.format(receiver.unum(), receive_point)) continue - ball_move_dist = wm.ball().pos().dist(receive_point) + ball_move_dist = wm.ball()._pos.dist(receive_point) if ball_move_dist < min_pass_dist or max_pass_dist < ball_move_dist: if debug_pass: @@ -319,16 +319,17 @@ def generate_through_pass(self, wm: 'WorldModel', receiver: 'PlayerObject'): continue nearest_receiver = Tools.get_nearest_teammate(wm, receive_point, self.receivers) - if nearest_receiver.unum() != receiver.unum(): - if debug_pass: - log.sw_log().pass_().add_text( - '#####TPass to {} {}, {} is closer than receiver '.format(receiver.unum(), receive_point, - nearest_receiver.unum())) - continue + if nearest_receiver is not None: + if nearest_receiver.unum() != receiver.unum(): + if debug_pass: + log.sw_log().pass_().add_text( + '#####TPass to {} {}, {} is closer than receiver '.format(receiver.unum(), receive_point, + nearest_receiver.unum())) + continue receiver_step = self.predict_receiver_reach_step(receiver, receive_point, True, 'T') + move_dist_penalty_step - ball_move_angle = (receive_point - wm.ball().pos()).th() + ball_move_angle = (receive_point - wm.ball()._pos).th() min_ball_step = sp.ball_move_step(sp.ball_speed_max(), ball_move_dist) @@ -350,8 +351,8 @@ def predict_receiver_reach_step(self, receiver, pos: Vector2D, use_penalty, pass ptype = receiver.player_type() target_dist = receiver.inertia_point(1).dist(pos) - n_turn = 1 if receiver.body_count() > 0 else Tools.predict_player_turn_cycle(ptype, receiver.body(), - receiver.vel().r(), target_dist, ( + n_turn = 1 if receiver.body_count() > 0 else Tools.predict_player_turn_cycle(ptype, receiver._body, + receiver._vel_r, target_dist, ( pos - receiver.inertia_point( 1)).th(), ptype.kickable_area(), False) @@ -363,9 +364,9 @@ def predict_receiver_reach_step(self, receiver, pos: Vector2D, use_penalty, pass if pass_type == 'L': dash_dist *= 1.05 - dash_angle = (pos - receiver.pos()).th() + dash_angle = (pos - receiver._pos).th() - if dash_angle.abs() > 90.0 or receiver.body_count() > 1 or (dash_angle - receiver.body()).abs() > 30.0: + if dash_angle.abs() > 90.0 or receiver.body_count() > 1 or (dash_angle - receiver._body).abs() > 30.0: n_turn += 1 n_dash = ptype.cycles_to_reach_distance(dash_dist) @@ -437,7 +438,7 @@ def create_pass(self, wm: 'WorldModel', receiver, receive_point: Vector2D, kick_count = Tools.predict_kick_count(wm, wm.self().unum(), first_ball_speed, ball_move_angle) - o_step, o_unum, o_intercepted_pos = self.predict_opponents_reach_step(wm, wm.ball().pos(), + o_step, o_unum, o_intercepted_pos = self.predict_opponents_reach_step(wm, wm.ball()._pos, first_ball_speed, ball_move_angle, receive_point, step + (kick_count - 1) + 5, description) @@ -521,7 +522,7 @@ def predict_opponent_reach_step(self, wm: 'WorldModel', opp: 'PlayerObject', fir opponent = opp ptype = opponent.player_type() - min_cycle = Tools.estimate_min_reach_cycle(opponent.pos(), ptype.real_speed_max(), first_ball_pos, + min_cycle = Tools.estimate_min_reach_cycle(opponent._pos, ptype.real_speed_max(), first_ball_pos, ball_move_angle) if min_cycle < 0: @@ -531,7 +532,7 @@ def predict_opponent_reach_step(self, wm: 'WorldModel', opp: 'PlayerObject', fir ball_pos = smath.inertia_n_step_point(first_ball_pos, first_ball_vel, cycle, sp.ball_decay()) control_area = sp.catchable_area() if opponent.is_goalie() and penalty_area.contains(ball_pos) else ptype.kickable_area() - inertia_pos = ptype.inertia_point(opponent.pos(), opponent.vel(), cycle) + inertia_pos = ptype.inertia_point(opponent._pos, opponent._vel, cycle) target_dist = inertia_pos.dist(ball_pos) dash_dist = target_dist @@ -565,7 +566,7 @@ def predict_opponent_reach_step(self, wm: 'WorldModel', opp: 'PlayerObject', fir n_turn = 0 if opponent.body_count() > 1: - n_turn = Tools.predict_player_turn_cycle(ptype, opponent.body(), opponent.vel().r(), target_dist, + n_turn = Tools.predict_player_turn_cycle(ptype, opponent._body, opponent._vel_r, target_dist, (ball_pos - inertia_pos).th(), control_area, True) n_step = n_turn + n_dash if n_turn == 0 else n_turn + n_dash + 1 diff --git a/base/goalie_decision.py b/base/goalie_decision.py index 16c234a9..59a1c811 100644 --- a/base/goalie_decision.py +++ b/base/goalie_decision.py @@ -27,7 +27,7 @@ from lib.player.player_agent import PlayerAgent -DEBUG = True +DEBUG = False def decision(agent: 'PlayerAgent'): SP = ServerParam.i() diff --git a/lib/action/basic_actions.py b/lib/action/basic_actions.py index 31324ac0..b90aa370 100644 --- a/lib/action/basic_actions.py +++ b/lib/action/basic_actions.py @@ -27,12 +27,12 @@ def __init__(self, point: Vector2D, cycle: int = 1): def execute(self, agent: 'PlayerAgent'): me = agent.world().self() - - if not me.pos().is_valid(): + + if not me._pos.is_valid(): return agent.do_turn(60) my_point = me.inertia_point(self._cycle) - target_rel_angle = (self._point - my_point).th() - me.body() + target_rel_angle = (self._point - my_point).th() - me._body agent.do_turn(target_rel_angle) if target_rel_angle.abs() < 1: @@ -58,7 +58,7 @@ def execute(self, agent: 'PlayerAgent'): # agent.do_turn(0.0) # return False - agent.do_turn(self._angle - me.body()) + agent.do_turn(self._angle - me._body) return True @@ -74,7 +74,7 @@ def __init__(self, cycle: int = 1): self._cycle = cycle def execute(self, agent: 'PlayerAgent'): - if not agent.world().ball().posValid(): + if not agent.world().ball().pos_valid(): return False ball_point = agent.world().ball().inertia_point(self._cycle) @@ -102,8 +102,8 @@ def execute(self, agent: 'PlayerAgent'): if wm.self().tackle_probability() < self._min_prob: return False - target_angle = (self._point - wm.ball().pos()).th() - target_rel_angle = target_angle - wm.self().body() + target_angle = (self._point - wm.ball()._pos).th() + target_rel_angle = target_angle - wm.self()._body # if agent.config().version() < 12.0: # if target_rel_angle.abs() < 90.0: @@ -113,14 +113,14 @@ def execute(self, agent: 'PlayerAgent'): # return agent.do_tackle(- sp.maxBackTacklePower()) # return False - ball_rel_angle = wm.ball().rpos().th() - wm.self().body() + ball_rel_angle = wm.ball()._rpos.th() - wm.self()._body eff_power = sp.max_back_tackle_power() + ( (sp.max_tackle_power() - sp.max_back_tackle_power()) * (1.0 - target_rel_angle.abs() / 180.0)) eff_power *= sp.tackle_power_rate() eff_power *= 1.0 - 0.5 * (ball_rel_angle.abs() / 180.0) - vel = wm.ball().vel() + Vector2D.polar2vector(eff_power, target_angle) + vel = wm.ball()._vel + Vector2D.polar2vector(eff_power, target_angle) if ((vel.th() - target_angle).abs() > 90.0 # never accelerate to the target direction or vel.r() < self._min_speed): # too small speed @@ -199,6 +199,6 @@ class ArmOff(ArmAction): """ def execute(self, agent: 'PlayerAgent'): - if agent.world().self().arm_movable() > 0: + if agent.world().self()._arm_movable > 0: return False - return agent.doPointtoOff() + return agent.do_pointto_off() diff --git a/lib/action/go_to_point.py b/lib/action/go_to_point.py index f9c30b1c..9fbebec5 100644 --- a/lib/action/go_to_point.py +++ b/lib/action/go_to_point.py @@ -6,6 +6,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: from lib.player.world_model import WorldModel + from lib.player.player_agent import PlayerAgent class GoToPoint: _dir_thr: float @@ -20,7 +21,7 @@ def __init__(self, target, dist_thr, max_dash_power, dash_speed=-1.0, cycle=100, self._dir_thr = dir_thr self._back_mode = False - def execute(self, agent): + def execute(self, agent: 'PlayerAgent'): if math.fabs(self._max_dash_power) < 0.1 or math.fabs(self._dash_speed) < 0.01: agent.do_turn(0) return True @@ -52,7 +53,7 @@ def do_turn(self, agent): target_rel: Vector2D = self._target - inertia_pos target_dist = target_rel.r() max_turn = wm.self().player_type().effective_turn(SP.i().max_moment(), wm.self().vel().r()) - turn_moment: AngleDeg = target_rel.th() - wm.self().body() + turn_moment: AngleDeg = target_rel.th() - wm.self()._body if turn_moment.abs() > max_turn and turn_moment.abs() > 90.0 and target_dist < 2.0 and wm.self().stamina_model().stamina() > SP.i().recover_dec_thr_value() + 500.0: effective_power = SP.i().max_dash_power() * wm.self().dash_rate() effective_back_power = SP.i().min_dash_power() * wm.self().dash_rate() @@ -112,8 +113,8 @@ def check_collision(self, agent): goal_post_r = Vector2D(-SP.i().pitch_half_length() + SP.i().goal_post_radius(), +SP.i().goal_half_width() + SP.i().goal_post_radius()) - dist_post_l = wm.self().pos().dist2(goal_post_l) - dist_post_r = wm.self().pos().dist2(goal_post_r) + dist_post_l = wm.self()._pos.dist2(goal_post_l) + dist_post_r = wm.self()._pos.dist2(goal_post_r) nearest_post = goal_post_l if dist_post_l > dist_post_r: @@ -124,14 +125,14 @@ def check_collision(self, agent): return post_circle = Circle2D(nearest_post, collision_dist) - move_line = Segment2D(wm.self().pos(), self._target) + move_line = Segment2D(wm.self()._pos, self._target) if len(post_circle.intersection(move_line)) == 0: return - post_angle: AngleDeg = AngleDeg((nearest_post - wm.self().pos()).th()) + post_angle: AngleDeg = AngleDeg((nearest_post - wm.self()._pos).th()) new_target: Vector2D = nearest_post - if post_angle.is_left_of(wm.self().body()): + if post_angle.is_left_of(wm.self()._body): new_target += Vector2D.from_polar(collision_dist + 0.1, post_angle + 90.0) else: new_target += Vector2D.from_polar(collision_dist + 0.1, post_angle - 90.0) diff --git a/lib/action/hold_ball.py b/lib/action/hold_ball.py index 1ff1850a..5c93dd97 100644 --- a/lib/action/hold_ball.py +++ b/lib/action/hold_ball.py @@ -111,11 +111,11 @@ def avoidOpponent(self, agent: 'PlayerAgent'): if not point.is_valid(): log.sw_log().kick().add_text( "avoidOpponent() no candidate point") return False - ball_move = point - wm.ball().pos() - kick_accel = ball_move - wm.ball().vel() + ball_move = point - wm.ball()._pos + kick_accel = ball_move - wm.ball()._vel kick_accel_r = kick_accel.r() agent.do_kick(kick_accel_r / wm.self().kick_rate(), - kick_accel.th() - wm.self().body()) + kick_accel.th() - wm.self()._body) return True """ @@ -157,27 +157,27 @@ def createKeepPoints(self, wm: 'WorldModel', candidates): # candidates = [] * dir_divs * 2 - my_next = wm.self().pos() + wm.self().vel() + my_next = wm.self()._pos + wm.self()._vel - my_noise = wm.self().vel().r() * param.player_rand() - current_dir_diff_rate = (wm.ball().angle_from_self() - wm.self().body()).abs() / 180.0 + my_noise = wm.self()._vel_r * param.player_rand() + current_dir_diff_rate = (wm.ball().angle_from_self() - wm.self()._body).abs() / 180.0 current_dist_rate = ( wm.ball().dist_from_self() - wm.self().player_type().player_size() - param.ball_size()) / wm.self().player_type().kickable_margin() current_pos_rate = 0.5 + 0.25 * (current_dir_diff_rate + current_dist_rate) - current_speed_rate = 0.5 + 0.5 * (wm.ball().vel().r() / (param.ball_speed_max() * param.ball_decay())) + current_speed_rate = 0.5 + 0.5 * (wm.ball()._vel_r / (param.ball_speed_max() * param.ball_decay())) angles = [-180 + a*dir_step for a in range(dir_divs)] for d in angles: angle = AngleDeg(d) - dir_diff = (angle - wm.self().body()).abs() + dir_diff = (angle - wm.self()._body).abs() unit_pos = Vector2D.polar2vector(1.0, angle) # near side point near_pos = my_next + unit_pos.set_length_vector(near_dist) if (near_pos.abs_x() < max_pitch_x and near_pos.abs_y() < max_pitch_y): - ball_move = near_pos - wm.ball().pos() - kick_accel = ball_move - wm.ball().vel() + ball_move = near_pos - wm.ball()._pos + kick_accel = ball_move - wm.ball()._vel # can kick to the point by 1 step kick if kick_accel.r() < param.max_power() * wm.self().kick_rate(): @@ -191,8 +191,8 @@ def createKeepPoints(self, wm: 'WorldModel', candidates): mid_pos = my_next + unit_pos.set_length_vector(mid_dist) if (mid_pos.abs_x() < max_pitch_x and mid_pos.abs_y() < max_pitch_y): - ball_move = mid_pos - wm.ball().pos() - kick_accel = ball_move - wm.ball().vel() + ball_move = mid_pos - wm.ball()._pos + kick_accel = ball_move - wm.ball()._vel kick_power = kick_accel.r() / wm.self().kick_rate() # can kick to the point by 1 step kick @@ -217,8 +217,8 @@ def createKeepPoints(self, wm: 'WorldModel', candidates): far_pos = my_next + unit_pos.set_length_vector(far_dist) if (far_pos.abs_x() < max_pitch_x and far_pos.abs_y() < max_pitch_y): - ball_move = far_pos - wm.ball().pos() - kick_accel = ball_move - wm.ball().vel() + ball_move = far_pos - wm.ball()._pos + kick_accel = ball_move - wm.ball()._vel kick_power = kick_accel.r() / wm.self().kick_rate() # can kick to the point by 1 step kick @@ -249,7 +249,7 @@ def evaluateKeepPoints(self, wm: 'WorldModel', keep_points): for it in keep_points: it.score_ = self.evaluateKeepPoint(wm, it.pos_) if it.score_ < DEFAULT_SCORE: - it.score_ += it.pos_.dist(wm.ball().pos()) + it.score_ += it.pos_.dist(wm.ball()._pos) else: it.score_ += it.kick_rate_ * 1000.0 @@ -271,7 +271,7 @@ def evaluateKeepPoint(self, wm: 'WorldModel', param = ServerParam.i() score = DEFAULT_SCORE - my_next = wm.self().pos() + wm.self().vel() + my_next = wm.self()._pos + wm.self()._vel if len(wm.opponents_from_ball()) == 0: return score for o in wm.opponents_from_ball(): @@ -287,9 +287,9 @@ def evaluateKeepPoint(self, wm: 'WorldModel', continue player_type = o.player_type() - opp_next = o.pos() + o.vel() + opp_next = o._pos + o._vel control_area = o.player_type().catchable_area() if ( - o.goalie() and penalty_area.contains(o.pos()) and penalty_area.contains( + o.goalie() and penalty_area.contains(o._pos) and penalty_area.contains( keep_point)) else o.player_type().kickable_area() opp_dist = opp_next.dist(keep_point) @@ -306,10 +306,10 @@ def evaluateKeepPoint(self, wm: 'WorldModel', score -= 25.0 if o.body_count() == 0: - opp_body = o.body() + opp_body = o._body - elif o.vel().r() > 0.2: # o.velCount() <= 1 #and - opp_body = o.vel().th() + elif o._vel_r > 0.2: # o.velCount() <= 1 #and + opp_body = o._vel_th else: opp_body = (my_next - opp_next).th() @@ -361,7 +361,7 @@ def evaluateKeepPoint(self, wm: 'WorldModel', and player_2_pos.x() - max_accel < param.tackle_dist() - 0.25): score -= 10.0 - ball_move_dist = (keep_point - wm.ball().pos()).r() + ball_move_dist = (keep_point - wm.ball()._pos).r() if ball_move_dist > wm.self().player_type().kickable_area() * 1.6: next_ball_dist = my_next.dist(keep_point) threshold = wm.self().player_type().kickable_area() - 0.4 @@ -380,15 +380,15 @@ def turnToPoint(self, agent: 'PlayerAgent'): max_pitch_x = param.pitch_half_length() - 0.2 max_pitch_y = param.pitch_half_width() - 0.2 wm = agent.world() - my_next = wm.self().pos() + wm.self().vel() - ball_next = wm.ball().pos() + wm.ball().vel() + my_next = wm.self()._pos + wm.self()._vel + ball_next = wm.ball()._pos + wm.ball()._vel if (ball_next.abs_x() > max_pitch_x or ball_next.abs_y() > max_pitch_y): return False - my_noise = wm.self().vel().r() * param.player_rand() - ball_noise = wm.ball().vel().r() * param.ball_rand() + my_noise = wm.self()._vel_r * param.player_rand() + ball_noise = wm.ball()._vel_r * param.ball_rand() next_ball_dist = my_next.dist(ball_next) @@ -406,7 +406,7 @@ def turnToPoint(self, agent: 'PlayerAgent'): my_inertia = wm.self().inertia_final_point() target_angle = (face_point - my_inertia).th() - if (wm.self().body() - target_angle).abs() < 5.0: + if (wm.self()._body - target_angle).abs() < 5.0: return False score = self.evaluateKeepPoint(wm, ball_next) @@ -430,16 +430,16 @@ def keepFront(self, agent: 'PlayerAgent'): wm = agent.world() front_keep_dist = wm.self().player_type().player_size() + param.ball_size() + 0.05 - my_next = wm.self().pos() + wm.self().vel() + my_next = wm.self()._pos + wm.self()._vel - front_pos = my_next + Vector2D.polar2vector(front_keep_dist, wm.self().body()) + front_pos = my_next + Vector2D.polar2vector(front_keep_dist, wm.self()._body) if (front_pos.abs_x() > max_pitch_x or front_pos.abs_y() > max_pitch_y): return False - ball_move = front_pos - wm.ball().pos() - kick_accel = ball_move - wm.ball().vel() + ball_move = front_pos - wm.ball()._pos + kick_accel = ball_move - wm.ball()._vel kick_power = kick_accel.r() / wm.self().kick_rate() # can kick to the point by 1 step kick @@ -452,7 +452,7 @@ def keepFront(self, agent: 'PlayerAgent'): return False agent.do_kick(kick_power, - kick_accel.th() - wm.self().body()) + kick_accel.th() - wm.self()._body) return True """ @@ -469,20 +469,20 @@ def keepReverse(self, agent: 'PlayerAgent'): max_pitch_y = param.pitch_half_width() - 0.2 wm = agent.world() - my_inertia = wm.self().pos() + wm.self().vel() + my_inertia = wm.self()._pos + wm.self()._vel - my_noise = wm.self().vel().r() * param.player_rand() - current_dir_diff_rate = (wm.ball().angle_from_self() - wm.self().body()).abs() / 180.0 + my_noise = wm.self()._vel_r * param.player_rand() + current_dir_diff_rate = (wm.ball().angle_from_self() - wm.self()._body).abs() / 180.0 current_dist_rate = (wm.ball().dist_from_self() - wm.self().player_type().player_size() - param.ball_size()) / wm.self().player_type().kickable_margin() current_pos_rate = 0.5 + 0.25 * (current_dir_diff_rate + current_dist_rate) - current_speed_rate = 0.5 + 0.5 * (wm.ball().vel().r() / (param.ball_speed_max() * param.ball_decay())) + current_speed_rate = 0.5 + 0.5 * (wm.ball()._vel_r / (param.ball_speed_max() * param.ball_decay())) keep_angle = (my_inertia - self._kick_target_point).th() - dir_diff = (keep_angle - wm.self().body()).abs() + dir_diff = (keep_angle - wm.self()._body).abs() min_dist = (wm.self().player_type().player_size() + param.ball_size() + 0.2) @@ -498,8 +498,8 @@ def keepReverse(self, agent: 'PlayerAgent'): or keep_pos.abs_y() > max_pitch_y): continue - ball_move = keep_pos - wm.ball().pos() - kick_accel = ball_move - wm.ball().vel() + ball_move = keep_pos - wm.ball()._pos + kick_accel = ball_move - wm.ball()._vel kick_power = kick_accel.r() / wm.self().kick_rate() if kick_power > param.max_power(): @@ -520,7 +520,7 @@ def keepReverse(self, agent: 'PlayerAgent'): score = self.evaluateKeepPoint(wm, keep_pos) if score >= DEFAULT_SCORE: agent.do_kick(kick_power, - kick_accel.th() - wm.self().body()) + kick_accel.th() - wm.self()._body) return True return False diff --git a/lib/action/intercept.py b/lib/action/intercept.py index 4b79342b..38b997f5 100644 --- a/lib/action/intercept.py +++ b/lib/action/intercept.py @@ -52,7 +52,7 @@ def execute(self, agent: 'PlayerAgent'): if best_intercept.dash_cycle() == 0: face_point = self._face_point.copy() if not face_point.is_valid(): - face_point.assign(50.5, wm.self().pos().y() * 0.75) + face_point.assign(50.5, wm.self()._pos.y() * 0.75) log.sw_log().intercept().add_text( f"best_intercept.dash_cycle() == 0 (TurnToPoint)") @@ -72,7 +72,7 @@ def execute(self, agent: 'PlayerAgent'): log.sw_log().intercept().add_text( f"best_intercept.turn_cycle() > 0 (do_turn)") - return agent.do_turn(target_angle - wm.self().body()) + return agent.do_turn(target_angle - wm.self()._body) if self.do_wait_turn(agent, target_point, best_intercept): return True @@ -106,8 +106,8 @@ def do_kickable_opponent_check(self, opp: PlayerObject = wm.opponents_from_ball()[0] if opp is not None: goal_pos = Vector2D(-ServerParam.i().pitch_half_length(), 0) - my_next = wm.self().pos() + wm.self().vel() - attack_pos = opp.pos() + opp.vel() + my_next = wm.self()._pos + wm.self()._vel + attack_pos = opp._pos + opp._vel if attack_pos.dist2(goal_pos) > my_next.dist2(goal_pos): log.sw_log().intercept().add_text( @@ -171,7 +171,7 @@ def get_best_intercept(self, wm: 'WorldModel', cycle = cache[i].reach_cycle() self_pos = wm.self().inertia_point(cycle) ball_pos = wm.ball().inertia_point(cycle) - ball_vel = wm.ball().vel() * SP.ball_decay() ** cycle + ball_vel = wm.ball()._vel * SP.ball_decay() ** cycle if ball_pos.abs_x() > max_pitch_x or \ ball_pos.abs_y() > max_pitch_y: @@ -252,7 +252,7 @@ def get_best_intercept(self, wm: 'WorldModel', return attacker_best if noturn_best is not None and forward_best is not None: - noturn_ball_vel = (wm.ball().vel() + noturn_ball_vel = (wm.ball()._vel * SP.ball_decay() ** noturn_best.reach_cycle()) noturn_ball_speed = noturn_ball_vel.r() if (noturn_ball_vel.x() > 0.1 @@ -264,7 +264,7 @@ def get_best_intercept(self, wm: 'WorldModel', return forward_best fastest_pos = wm.ball().inertia_point(cache[0].reach_cycle()) - fastest_vel = wm.ball().vel() * SP.ball_decay() ** cache[0].reach_cycle() + fastest_vel = wm.ball()._vel * SP.ball_decay() ** cache[0].reach_cycle() if ((fastest_pos.x() > -33 or fastest_pos.abs_y() > 20) @@ -282,13 +282,13 @@ def get_best_intercept(self, wm: 'WorldModel', return noturn_best if nearest_best.reach_cycle() <= noturn_best.reach_cycle() + 2: - nearest_ball_vel = (wm.ball().vel() + nearest_ball_vel = (wm.ball()._vel * SP.ball_decay() ** nearest_best.reach_cycle()) nearest_ball_speed = nearest_ball_vel.r() if nearest_ball_speed < 0.7: return nearest_best - noturn_ball_vel = (wm.ball().vel() + noturn_ball_vel = (wm.ball()._vel * SP.ball_decay() ** noturn_best.reach_cycle()) if (nearest_best.ball_dist() < wm.self().player_type().kickable_area() - 0.4 and nearest_best.ball_dist() < noturn_best.ball_dist() @@ -309,9 +309,9 @@ def get_best_intercept(self, wm: 'WorldModel', if nearest_best is not None: return nearest_best - if (wm.self().pos().x() > 40 - and wm.ball().vel().r() > 1.8 - and wm.ball().vel().th().abs() < 100 + if (wm.self()._pos.x() > 40 + and wm.ball()._vel_r > 1.8 + and wm.ball()._vel_th.abs() < 100 and cache[0].reach_cycle() > 1): chance_best: InterceptInfo = None for i in range(MAX): @@ -337,10 +337,10 @@ def do_wait_turn(self, return False my_inertia = wm.self().inertia_point(info.reach_cycle()) - target_rel = (target_point - my_inertia).rotated_vector(-wm.self().body()) + target_rel = (target_point - my_inertia).rotated_vector(-wm.self()._body) target_dist = target_rel.r() - ball_travel = inertia_n_step_distance(wm.ball().vel().r(), + ball_travel = inertia_n_step_distance(wm.ball()._vel_r, info.reach_cycle(), ServerParam.i().ball_decay()) ball_noise = ball_travel * ServerParam.i().ball_rand() @@ -348,7 +348,7 @@ def do_wait_turn(self, if info.reach_cycle() == 1 and info.turn_cycle() == 1: face_point = self._face_point if not face_point.is_valid(): - face_point.assign(50.5, wm.self().pos().y() * 0.9) + face_point.assign(50.5, wm.self()._pos.y() * 0.9) log.sw_log().intercept().add_text( f"do wait turn (1) (TurnToPoint)") @@ -360,7 +360,7 @@ def do_wait_turn(self, return True extra_buf = 0.1 * bound(0, info.reach_cycle() - 1, 4) - angle_diff = (wm.ball().vel().th() - wm.self().body()).abs() + angle_diff = (wm.ball()._vel_th - wm.self()._body).abs() if angle_diff < 10 or 170 < angle_diff: extra_buf = 0 @@ -372,12 +372,12 @@ def do_wait_turn(self, face_point = self._face_point if info.reach_cycle() > 2: - face_point = my_inertia + (wm.ball().pos() - my_inertia).rotated_vector(90) + face_point = my_inertia + (wm.ball()._pos - my_inertia).rotated_vector(90) if face_point.x() < my_inertia.x(): - face_point = my_inertia + (wm.ball().pos() - my_inertia).rotated_vector(-90) + face_point = my_inertia + (wm.ball()._pos - my_inertia).rotated_vector(-90) if not face_point.is_valid(): - face_point.assign(50.5, wm.self().pos().y() * 0.9) + face_point.assign(50.5, wm.self()._pos.y() * 0.9) face_rel = face_point - my_inertia face_angle = face_rel.th() @@ -407,17 +407,17 @@ def do_inertia_dash(self, agent.do_dash(info.dash_power(), info.dash_angle()) return True - target_rel = target_point - wm.self().pos() - target_rel.rotate(-wm.self().body()) + target_rel = target_point - wm.self()._pos + target_rel.rotate(-wm.self()._body) accel_angle = wm.self().body() if info.dash_power() < 0: accel_angle += 180 - ball_vel = wm.ball().vel() * ServerParam.i().ball_decay() ** info.reach_cycle() + ball_vel = wm.ball()._vel * ServerParam.i().ball_decay() ** info.reach_cycle() if ((not wm.self().goalie() or wm.last_kicker_side() == wm.our_side()) - and wm.self().body().abs() < 50): + and wm.self()._body.abs() < 50): buf = 0.3 if info.reach_cycle() >= 8: buf = 0 @@ -448,7 +448,7 @@ def do_inertia_dash(self, used_power = info.dash_power() if (wm.ball().seen_pos_count() <= 2 - and wm.ball().vel().r() * ServerParam.i().ball_decay() ** info.reach_cycle() < ptype.kickable_area() * 1.5 + and wm.ball()._vel_r * ServerParam.i().ball_decay() ** info.reach_cycle() < ptype.kickable_area() * 1.5 and info.dash_angle().abs() < 5 and target_rel.abs_x() < (ptype.kickable_area() + ptype.dash_rate(wm.self().effort()) @@ -460,7 +460,7 @@ def do_inertia_dash(self, first_speed = min_max(-ptype.player_speed_max(), first_speed, ptype.player_speed_max()) - rel_vel = wm.self().vel().rotated_vector(-wm.self().body()) + rel_vel = wm.self()._vel.rotated_vector(-wm.self()._body) required_accel = first_speed - rel_vel.x() used_power = required_accel / wm.self().dash_rate() used_power /= ServerParam.i().dash_dir_rate(info.dash_angle().degree()) @@ -475,10 +475,10 @@ def do_inertia_dash(self, my_inertia = wm.self().inertia_point(info.reach_cycle()) face_point = self._face_point if not face_point.is_valid(): - face_point.assign(50.5, wm.self().pos().y() * 0.75) + face_point.assign(50.5, wm.self()._pos.y() * 0.75) face_angle = (face_point - my_inertia).th() - ball_next = wm.ball().pos() + wm.ball().vel() + ball_next = wm.ball()._pos + wm.ball()._vel ball_angle = (ball_next - my_inertia).th() # normal_half_width = ViewWidth.width(ViewWidth.Mode.NORMAL) # TODO FIX THIS after view mode normal_half_width = ServerParam.i().visible_angle() diff --git a/lib/action/intercept_info.py b/lib/action/intercept_info.py index 64595297..a23df162 100644 --- a/lib/action/intercept_info.py +++ b/lib/action/intercept_info.py @@ -67,11 +67,11 @@ def stamina(self): return self._stamina @staticmethod - def compare(lhs, rhs): + def compare(lhs: 'InterceptInfo', rhs: 'InterceptInfo'): return True if lhs.reach_cycle() < rhs.reach_cycle() else ( lhs.reach_cycle() == rhs.reach_cycle() and lhs.turn_cycle() < rhs.turn_cycle()) - def __lt__(self, other): + def __lt__(self, other: 'InterceptInfo'): if self.reach_cycle() < other.reach_cycle(): return True return self.reach_cycle() == other.reach_cycle() and self.turn_cycle() < other.turn_cycle() diff --git a/lib/action/intercept_player.py b/lib/action/intercept_player.py index d52d1664..69da5d9b 100644 --- a/lib/action/intercept_player.py +++ b/lib/action/intercept_player.py @@ -30,8 +30,8 @@ def predict(self, if player.seen_pos_count() <= player.pos_count() else player.pos()) min_cycle = 0 - ball_to_player = player_pos - wm.ball().pos() - ball_to_player.rotate(-wm.ball().vel().th()) + ball_to_player = player_pos - wm.ball()._pos + ball_to_player.rotate(-wm.ball()._vel_th) min_cycle = int(floor(ball_to_player.abs_y() / player_type.real_speed_max())) @@ -138,7 +138,7 @@ def predict_turn_cycle(self, turn_margin = AngleDeg.asin_deg(control_area / target_dist) turn_margin = max(turn_margin, 12) - angle_diff = (target_rel.th() - player.body()).abs() + angle_diff = (target_rel.th() - player._body).abs() if (target_dist < 5 # XXX MAGIC NUMBER XXX :| and angle_diff > 90): @@ -146,7 +146,7 @@ def predict_turn_cycle(self, angle_diff = 180 - angle_diff n_turn = 0 - speed = player.vel().r() + speed = player._vel.r() while angle_diff > turn_margin: max_turn = player_type.effective_turn(ServerParam.i().max_moment(), speed) diff --git a/lib/action/intercept_self.py b/lib/action/intercept_self.py index 9eaadc6a..c4714372 100644 --- a/lib/action/intercept_self.py +++ b/lib/action/intercept_self.py @@ -19,7 +19,7 @@ control_area_buf = 0.15 -DEBUG = True +DEBUG = False class SelfIntercept: @@ -49,7 +49,7 @@ def predict(self, max_cycle, self_cache: list): def predict_one_step(self, self_cache): wm = self._wm - ball_next: Vector2D = wm.ball().pos() + wm.ball().vel() + ball_next: Vector2D = wm.ball()._pos + wm.ball()._vel goalie_mode: bool = self.is_goalie_mode(ball_next) control_area: float = wm.self().player_type().catchable_area() if \ goalie_mode else \ @@ -71,14 +71,14 @@ def predict_no_dash(self, self_cache) -> bool: wm: 'WorldModel' = self._wm me: PlayerObject = wm.self() - my_next: Vector2D = me.pos() + me.vel() - ball_next: Vector2D = wm.ball().pos() + wm.ball().vel() + my_next: Vector2D = me._pos + me._vel + ball_next: Vector2D = wm.ball()._pos + wm.ball()._vel goalie_mode: bool = self.is_goalie_mode(ball_next) control_area: float = me.player_type().catchable_area() if \ goalie_mode else \ me.player_type().kickable_area() next_ball_rel: Vector2D = (ball_next - my_next).rotated_vector(-me.body()) - ball_noise: float = wm.ball().vel().r() * SP.ball_rand() + ball_noise: float = wm.ball()._vel_r * SP.ball_rand() next_ball_dist: float = next_ball_rel.r() # out of control area @@ -105,7 +105,7 @@ def predict_no_dash(self, self_cache) -> bool: if next_ball_dist > ptype.player_size() + SP.ball_size(): kick_rate: float = ptype.kick_rate(next_ball_dist, next_ball_rel.th().degree()) - next_ball_vel: Vector2D = wm.ball().vel() * SP.ball_decay() + next_ball_vel: Vector2D = wm.ball()._vel * SP.ball_decay() if SP.max_power() * kick_rate <= next_ball_vel.r() * SP.ball_decay() * 1.1: log.sw_log().intercept().add_text("------>>>>> NO can not control the ball") return False @@ -143,7 +143,7 @@ def predict_one_dash(self, self_cache): me: PlayerObject = wm.self() ptype: PlayerType = me.player_type() - ball_next: Vector2D = ball.pos() + ball.vel() + ball_next: Vector2D = ball._pos + ball._vel goalie_mode: bool = self.is_goalie_mode(ball_next) control_area: float = ptype.catchable_area() if \ goalie_mode else \ @@ -175,8 +175,8 @@ def predict_one_dash(self, self_cache): dash_angle) max_back_accel = Vector2D.polar2vector(back_dash_power * dash_rate, dash_angle) - ptype.normalize_accel(me.vel(), max_forward_accel) - ptype.normalize_accel(me.vel(), max_back_accel) + ptype.normalize_accel(me._vel, max_forward_accel) + ptype.normalize_accel(me._vel, max_back_accel) info: InterceptInfo = InterceptInfo() if self.predict_one_dash_adjust(dash_angle, @@ -198,8 +198,8 @@ def predict_one_dash(self, self_cache): dash_angle) max_back_accel = Vector2D.polar2vector(SP.min_dash_power() * dash_rate, dash_angle) - ptype.normalize_accel(me.vel(), max_forward_accel) - ptype.normalize_accel(me.vel(), max_back_accel) + ptype.normalize_accel(me._vel, max_forward_accel) + ptype.normalize_accel(me._vel, max_back_accel) info: InterceptInfo = InterceptInfo() if self.predict_one_dash_adjust(dash_angle, @@ -235,8 +235,8 @@ def predict_one_dash_adjust(self, control_buf = control_area - 0.075 dash_dir: AngleDeg = dash_angle - me.body() - ball_next = wm.ball().pos() + wm.ball().vel() - me_next = me.pos() + me.vel() + ball_next = wm.ball()._pos + wm.ball()._vel + me_next = me._pos + me._vel ball_rel: Vector2D = (ball_next - me_next).rotated_vector(-dash_angle) forward_accel_rel: Vector2D = max_forward_accel.rotated_vector(-dash_angle) @@ -302,8 +302,8 @@ def predict_one_dash_adjust(self, mode = InterceptInfo.Mode.NORMAL accel = Vector2D.polar2vector(dash_power * dash_rate, dash_angle) - my_vel = me.vel() + accel - my_pos = me.pos() + my_vel + my_vel = me._vel + accel + my_pos = me._pos + my_vel stamina_model = me.stamina_model() stamina_model.simulate_dash(me.player_type(), dash_power) @@ -388,7 +388,7 @@ def predict_short_step(self, max_cycle, save_recovery, self_cache): pen_area_x = SP.our_penalty_area_line_x() - 0.5 pen_area_y = SP.penalty_area_half_width() - 0.5 - ball_to_self = (me.pos() - ball.pos()).rotated_vector(-ball.vel().th()) + ball_to_self = (me._pos - ball._pos).rotated_vector(-ball._vel_th) min_cycle = int(ceil((ball_to_self.abs_y() - ptype.kickable_area()) / ptype.real_speed_max())) @@ -398,7 +398,7 @@ def predict_short_step(self, max_cycle, save_recovery, self_cache): min_cycle = 2 ball_pos = ball.inertia_point(min_cycle - 1) - ball_vel = ball.vel() * SP.ball_decay() ** (min_cycle - 1) + ball_vel = ball._vel * SP.ball_decay() ** (min_cycle - 1) for cycle in range(min_cycle, max_loop + 1): tmp_cache = [] @@ -410,7 +410,7 @@ def predict_short_step(self, max_cycle, save_recovery, self_cache): control_area = (ptype.catchable_area() if goalie_mode else ptype.kickable_area()) - if (control_area + ptype.real_speed_max() * cycle) ** 2 < me.pos().dist2(ball_pos): + if (control_area + ptype.real_speed_max() * cycle) ** 2 < me._pos.dist2(ball_pos): log.sw_log().intercept().add_text("self pred short too far") continue @@ -441,7 +441,7 @@ def predict_short_step(self, max_cycle, save_recovery, self_cache): if len(tmp_cache) == 0: continue - safety_ball_dist = max(control_area - 0.2 - ball.pos().dist(ball_pos) * SP.ball_rand(), + safety_ball_dist = max(control_area - 0.2 - ball._pos.dist(ball_pos) * SP.ball_rand(), ptype.player_size() + SP.ball_size() + ptype.kickable_margin() * 0.4) best: InterceptInfo = tmp_cache[0] for it in tmp_cache[1:]: @@ -560,9 +560,9 @@ def predict_omni_dash_short(self, my_vel *= ptype.player_decay() stamina_model.simulate_dash(ptype, dash_power) - my_move = my_pos - me.pos() + my_move = my_pos - me._pos if my_pos.dist2(ball_pos) < (control_area - control_area_buf) ** 2 or \ - my_move.r() > (ball_pos - me.pos()).rotated_vector(-my_move.th()).abs_x(): + my_move.r() > (ball_pos - me._pos).rotated_vector(-my_move.th()).abs_x(): mode = (InterceptInfo.Mode.EXHAUST if stamina_model.recovery() < me.stamina_model().recovery() and not stamina_model.capacity_is_empty() @@ -685,7 +685,7 @@ def predict_dash_cycle_short(self, my_inertia = me.inertia_point(cycle) my_pos = me.inertia_point(n_turn) - my_vel = me.vel() * ptype.player_decay() ** n_turn + my_vel = me._vel * ptype.player_decay() ** n_turn stamina_model = me.stamina_model() stamina_model.simulate_waits(ptype, n_turn) @@ -745,7 +745,7 @@ def predict_dash_cycle_short(self, stamina_model.simulate_dash(ptype, dash_power) if my_pos.dist2(ball_pos) < (control_area - control_area_buf) ** 2 or \ - me.pos().dist2(my_pos) > me.pos().dist2(ball_pos): + me._pos.dist2(my_pos) > me._pos.dist2(ball_pos): mode = (InterceptInfo.Mode.EXHAUST if stamina_model.stamina() < SP.recover_dec_thr_value() and not stamina_model.capacity_is_empty() @@ -785,7 +785,7 @@ def predict_turn_cycle_short(self, turn_margin = max(self._min_turn_thr, AngleDeg.asin_deg(dist_thr / target_dist)) if angle_diff > turn_margin: - my_speed = me.vel().r() + my_speed = me._vel.r() while angle_diff > turn_margin: angle_diff -= ptype.effective_turn(max_moment, my_speed) my_speed *= ptype.player_decay() @@ -820,8 +820,8 @@ def predict_long_step(self, max_cycle: int, save_recovery: bool, self_cache: lis ptype = me.player_type() # calc y distance from ball line - ball_to_self = me.pos() - ball.pos() - ball_to_self.rotate(-ball.vel().th()) + ball_to_self = me._pos - ball._pos + ball_to_self.rotate(-ball._vel_th) start_cycle = int(ceil((ball_to_self.abs_y() - ptype.kickable_area() - 0.2) @@ -830,7 +830,7 @@ def predict_long_step(self, max_cycle: int, save_recovery: bool, self_cache: lis # start_cycle = self._max_short_step + 1 ball_pos = ball.inertia_point(start_cycle - 1) - ball_vel = ball.vel() * SP.ball_decay() ** (start_cycle - 1) + ball_vel = ball._vel * SP.ball_decay() ** (start_cycle - 1) found = False max_loop = max_cycle @@ -850,7 +850,7 @@ def predict_long_step(self, max_cycle: int, save_recovery: bool, self_cache: lis control_area = ptype.catchable_area() if goalie_mode else ptype.kickable_area() # reach point is to far never reach - if control_area + ptype.real_speed_max() * cycle < me.pos().dist(ball_pos): + if control_area + ptype.real_speed_max() * cycle < me._pos.dist(ball_pos): log.sw_log().intercept().add_text('-------> to far never reach') log.sw_log().intercept().add_circle(cx=ball_pos.x(), cy=ball_pos.y(), r=0.3, color='r') continue @@ -933,7 +933,7 @@ def predict_turn_cycle(self, cycle: int, # predict turn cycles max_moment = ServerParam.i().max_moment() * (1 - ServerParam.i().player_rand()) - player_speed = wm.self().vel().r() + player_speed = wm.self()._vel.r() while angle_diff > turn_margin: max_turnable = ptype.effective_turn(max_moment, player_speed) angle_diff -= max_turnable @@ -1007,8 +1007,8 @@ def can_reach_after_dash(self, recover_dec_thr = SP.recover_dec_thr() * SP.stamina_max() dash_angle_minus = -dash_angle - ball_rel = (ball_pos - wm.self().pos()).rotated_vector(dash_angle_minus) - ball_noise = (wm.ball().pos().dist(ball_pos) + ball_rel = (ball_pos - wm.self()._pos).rotated_vector(dash_angle_minus) + ball_noise = (wm.ball()._pos.dist(ball_pos) * SP.ball_rand() * 0.5) noised_ball_x = ball_rel.x() + ball_noise @@ -1016,7 +1016,7 @@ def can_reach_after_dash(self, # prepare loop variables # ORIGIN: first player pos. # X - axis: dash angle - tmp_pos = ptype.inertia_travel(wm.self().vel(), n_turn) + tmp_pos = ptype.inertia_travel(wm.self()._vel, n_turn) tmp_pos.rotate(dash_angle_minus) tmp_vel = wm.self().vel() @@ -1080,7 +1080,7 @@ def can_reach_after_dash(self, if tmp_pos.x() * PLAYER_NOISE_RATE + 0.1 > noised_ball_x: result_recovery = stamina_model.recovery() inertia_pos = ptype.inertia_point(tmp_pos, tmp_vel, n_dash - (i + 1)) - my_final_pos = wm.self().pos() + tmp_pos.rotate(dash_angle) + my_final_pos = wm.self()._pos + tmp_pos.rotate(dash_angle) if my_inertia.dist2(my_final_pos) > 0.01: my_final_pos = Line2D(p1=my_inertia, p2=my_final_pos).projection(ball_pos) stamina_model.simulate_waits(ptype, n_dash - (i + 1)) @@ -1105,7 +1105,7 @@ def can_reach_after_dash(self, buf += ball_noise if last_ball_dist < max(control_area - 0.225, control_area - buf): - my_final_pos = wm.self().pos() + tmp_pos.rotate(dash_angle) + my_final_pos = wm.self()._pos + tmp_pos.rotate(dash_angle) result_recovery = stamina_model.recovery() mode = (InterceptInfo.Mode.EXHAUST if stamina_model.recovery() < wm.self().recovery() diff --git a/lib/action/intercept_table.py b/lib/action/intercept_table.py index f8c90fa7..d0de0e6f 100644 --- a/lib/action/intercept_table.py +++ b/lib/action/intercept_table.py @@ -17,7 +17,7 @@ class InterceptTable: - DEBUG = True + DEBUG = False def __init__(self): self._last_update_time: GameTime = GameTime(-10, -100) @@ -81,7 +81,7 @@ def update(self, wm: 'WorldModel'): log.sw_log().intercept().add_text( "(intercept update) GAMEMODE RETURN") return - if not wm.self().pos().is_valid() or not wm.ball().pos().is_valid(): + if not wm.self()._pos.is_valid() or not wm.ball()._pos.is_valid(): log.sw_log().intercept().add_text( "(intercept update) self pos or ball pos is not valid") return diff --git a/lib/action/kick_table.py b/lib/action/kick_table.py index e7059e75..fa314d3c 100644 --- a/lib/action/kick_table.py +++ b/lib/action/kick_table.py @@ -338,7 +338,7 @@ def __init__(self): for j in range(NUM_STATE): self._state_cache[i].append(0.0) # not static state list - self._state_list = [] + self._state_list: list[State] = [] self._tables = [] self._current_state = State() @@ -474,7 +474,7 @@ def create_state_cache(self, world: 'WorldModel'): far_dist = calc_far_dist(self_type) rpos = world.ball().rpos() - rpos.rotate(- world.self().body()) + rpos.rotate(- world.self()._body) dist = rpos.r() angle = rpos.th() @@ -526,7 +526,7 @@ def create_state_cache(self, world: 'WorldModel'): pos = self._state_list[index].pos_.copy() krate = self_type.kick_rate(mid_dist, pos.th().degree()) - pos.rotate(world.self().body()) + pos.rotate(world.self()._body) pos.set_length(mid_dist) pos += self_pos @@ -541,7 +541,7 @@ def create_state_cache(self, world: 'WorldModel'): pos = self._state_list[index].pos_.copy() krate = self_type.kick_rate(far_dist, pos.th().degree()) - pos.rotate(world.self().body()) + pos.rotate(world.self()._body) pos.set_length(far_dist) pos += self_pos @@ -630,7 +630,7 @@ def check_interfere_at(world: 'WorldModel', if o.dist_from_ball() > 10.0: break - opp_next = o.pos() + o.vel() + opp_next = o._pos + o._vel opp_dist = opp_next.dist(state.pos_) if o.is_tackling(): @@ -642,7 +642,7 @@ def check_interfere_at(world: 'WorldModel', continue control_area = o.player_type().catchable_area() if ( - o.goalie() and penalty_area.contains(o.pos()) and penalty_area.contains(state.pos_ + o.goalie() and penalty_area.contains(o._pos) and penalty_area.contains(state.pos_ )) else o.player_type().kickable_area() # @@ -652,7 +652,7 @@ def check_interfere_at(world: 'WorldModel', flag |= KICKABLE break - opp_body = o.body() if o.body_count() <= 1 else (state.pos_ - opp_next).th() + opp_body = o._body if o.body_count() <= 1 else (state.pos_ - opp_next).th() player_2_pos = Vector2D(state.pos_ - opp_next) player_2_pos.rotate(- opp_body) # @@ -742,14 +742,14 @@ def check_interfere_after_release(self, *args): # , **kwargs):): break opp_pos = o.inertia_point(cycle) if not opp_pos.is_valid(): - opp_pos = o.pos() + o.vel() + opp_pos = o._pos + o._vel if o.is_tackling(): if opp_pos.dist(ball_pos) < (o.player_type().player_size() + ServerParam.i().ball_size()): state.flag_ |= RELEASE_INTERFERE continue control_area = o.player_type().catchable_area() if ( - o.goalie() and penalty_area.contains(o.pos()) and penalty_area.contains( + o.goalie() and penalty_area.contains(o._pos) and penalty_area.contains( state.pos_)) else o.player_type().kickable_area() control_area += 0.1 @@ -762,7 +762,7 @@ def check_interfere_after_release(self, *args): # , **kwargs):): else: state.flag_ |= RELEASE_INTERFERE else: # if cycle <= 1 : - opp_body = o.body() if o.body_count() <= 1 else (ball_pos - opp_pos).th() + opp_body = o._body if o.body_count() <= 1 else (ball_pos - opp_pos).th() player_2_pos = ball_pos - opp_pos player_2_pos.rotate(- opp_body) @@ -804,26 +804,26 @@ def simulate_one_step(self, world: 'WorldModel', target_point: Vector2D, first_s current_max_accel = min(self._current_state.kick_rate_ * ServerParam.i().max_power(), ServerParam.i().ball_accel_max()) - target_vel = (target_point - world.ball().pos()) + target_vel = (target_point - world.ball()._pos) target_vel.set_length(first_speed) - accel = target_vel - world.ball().vel() + accel = target_vel - world.ball()._vel accel_r = accel.r() if accel_r > current_max_accel: max_vel = calc_max_velocity(target_vel.th(), self._current_state.kick_rate_, - world.ball().vel()) - accel = max_vel - world.ball().vel() + world.ball()._vel) + accel = max_vel - world.ball()._vel self._candidates.append(Sequence()) self._candidates[-1].flag_ = self._current_state.flag_ - self._candidates[-1].pos_list_.append(world.ball().pos() + max_vel) + self._candidates[-1].pos_list_.append(world.ball()._pos + max_vel) self._candidates[-1].speed_ = max_vel.r() self._candidates[-1].power_ = accel.r() / self._current_state.kick_rate_ return False self._candidates.append(Sequence()) self._candidates[-1].flag_ = self._current_state.flag_ - self._candidates[-1].pos_list_.append(world.ball().pos() + target_vel) + self._candidates[-1].pos_list_.append(world.ball()._pos + target_vel) self._candidates[-1].speed_ = first_speed self._candidates[-1].power_ = accel_r / self._current_state.kick_rate_ """ @@ -858,8 +858,8 @@ def simulate_two_step(self, world: 'WorldModel', target_point: Vector2D, first_s param = ServerParam.i() my_kickable_area = self_type.kickable_area() - my_noise = world.self().vel().r() * param.player_rand() - current_dir_diff_rate = (world.ball().angle_from_self() - world.self().body()).abs() / 180.0 + my_noise = world.self()._vel_r * param.player_rand() + current_dir_diff_rate = (world.ball().angle_from_self() - world.self()._body).abs() / 180.0 current_dist_rate = ((world.ball().dist_from_self() - self_type.player_size() @@ -867,7 +867,7 @@ def simulate_two_step(self, world: 'WorldModel', target_point: Vector2D, first_s / self_type.kickable_margin()) current_pos_rate = 0.5 + 0.25 * (current_dir_diff_rate + current_dist_rate) - current_speed_rate = 0.5 + 0.5 * (world.ball().vel().r() / ( + current_speed_rate = 0.5 + 0.5 * (world.ball()._vel_r / ( param.ball_speed_max() * param.default_player_decay())) # my_final_pos = world.self().pos() + world.self().vel() + world.self().vel() * self_type.player_decay() @@ -891,8 +891,8 @@ def simulate_two_step(self, world: 'WorldModel', target_point: Vector2D, first_s kick_miss_flag = SAFETY target_vel = (target_point - state.pos_).set_length_vector(first_speed) - vel = state.pos_ - world.ball().pos() - accel = vel - world.ball().vel() + vel = state.pos_ - world.ball()._pos + accel = vel - world.ball()._vel accel_r = accel.r() if accel_r > current_max_accel: @@ -967,17 +967,17 @@ def simulate_three_step(self, world: 'WorldModel', my_kickable_area = self_type.kickable_area() - my_noise1 = world.self().vel().r() * param.player_rand() - current_dir_diff_rate = (world.ball().angle_from_self() - world.self().body()).abs() / 180.0 + my_noise1 = world.self()._vel_r * param.player_rand() + current_dir_diff_rate = (world.ball().angle_from_self() - world.self()._body).abs() / 180.0 current_dist_rate = ((world.ball().dist_from_self() - self_type.player_size() - param.ball_size()) / self_type.kickable_margin()) current_pos_rate = 0.5 + 0.25 * (current_dir_diff_rate + current_dist_rate) - current_speed_rate = 0.5 + 0.5 * (world.ball().vel().r() + current_speed_rate = 0.5 + 0.5 * (world.ball()._vel_r / (param.ball_speed_max() * param.ball_decay())) - target_rel_angle = (target_point - world.self().pos()).th() - world.self().body() + target_rel_angle = (target_point - world.self()._pos).th() - world.self()._body angle_deg = target_rel_angle.degree() + 180.0 target_angle_index = round(DEST_DIR_DIVS * (angle_deg / 360.0)) if target_angle_index >= DEST_DIR_DIVS: @@ -1020,8 +1020,8 @@ def simulate_three_step(self, world: 'WorldModel', kick_miss_flag = SAFETY - vel1 = state_1st.pos_ - world.ball().pos() - accel = vel1 - world.ball().vel() + vel1 = state_1st.pos_ - world.ball()._pos + accel = vel1 - world.ball()._vel accel_r2 = accel.r2() if accel_r2 > current_max_accel2: diff --git a/lib/action/neck_body_to_ball.py b/lib/action/neck_body_to_ball.py index 7b53cd3f..7422b7ad 100644 --- a/lib/action/neck_body_to_ball.py +++ b/lib/action/neck_body_to_ball.py @@ -19,7 +19,7 @@ def execute(self, agent: 'PlayerAgent'): log.debug_client().add_message('BodyToBall/') wm = agent.world() if wm.ball().pos_valid(): - ball_next = wm.ball().pos() + wm.ball().vel() + ball_next = wm.ball()._pos + wm.ball()._vel return NeckBodyToPoint(ball_next, self._angle_buf).execute(agent) return ScanField().execute(agent) diff --git a/lib/action/neck_body_to_point.py b/lib/action/neck_body_to_point.py index 89b26e3c..928349a2 100644 --- a/lib/action/neck_body_to_point.py +++ b/lib/action/neck_body_to_point.py @@ -27,15 +27,15 @@ def execute(self, agent: 'PlayerAgent'): angle_buf = bound(0., self._angle_buf, 180.) - my_next = wm.self().pos() + wm.self().vel() - target_rel_angle = (self._point - my_next).th() - wm.self().body() + my_next = wm.self()._pos + wm.self()._vel + target_rel_angle = (self._point - my_next).th() - wm.self()._body if SP.min_neck_angle() + angle_buf < target_rel_angle.degree() < SP.max_neck_angle() - angle_buf: agent.do_turn(0.) agent.set_neck_action(NeckTurnToRelative(target_rel_angle)) return True - max_turn = wm.self().player_type().effective_turn(SP.max_moment(),wm.self().vel().r()) + max_turn = wm.self().player_type().effective_turn(SP.max_moment(), wm.self()._vel_r) if target_rel_angle.abs() < max_turn: agent.do_turn(target_rel_angle) agent.set_neck_action(NeckTurnToRelative(0.)) diff --git a/lib/action/neck_scan_field.py b/lib/action/neck_scan_field.py index 4e0b92e5..80f150c8 100644 --- a/lib/action/neck_scan_field.py +++ b/lib/action/neck_scan_field.py @@ -15,7 +15,7 @@ class NeckScanField(NeckAction): - DEBUG = True + DEBUG = False INVALID_ANGLE = -360. @@ -175,7 +175,7 @@ def calc_angle_for_wide_pitch_edge(self, agent: 'PlayerAgent'): if gt is not GameModeType.PlayOn and not gt.is_goal_kick() and wm.ball().dist_from_self() > 2: return NeckScanField.INVALID_ANGLE - next_self_pos = wm.self().pos() + wm.self().vel() + next_self_pos = wm.self()._pos + wm.self()._vel pitch_x_thr = SP.pitch_half_length() - 15. pitch_y_thr = SP.pitch_half_length() - 10. # TODO WIDTH MAYBE(it was on librcsc tho...) diff --git a/lib/action/neck_scan_players.py b/lib/action/neck_scan_players.py index 866a6dfb..1d6daed2 100644 --- a/lib/action/neck_scan_players.py +++ b/lib/action/neck_scan_players.py @@ -17,7 +17,7 @@ from lib.player.player_agent import PlayerAgent class NeckScanPlayers(NeckAction): - DEBUG = True + DEBUG = False INVALID_ANGLE = -360.0 @@ -122,7 +122,7 @@ def calculate_score(wm: WorldModel, next_self_pos: Vector2D, left_angle: AngleDe if p.is_self(): continue - pos = p.pos() + p.vel() + pos = p._pos + p._vel angle = (pos - next_self_pos).th() if not angle.is_right_of(reduced_left_angle) or not angle.is_left_of(reduced_right_angle): @@ -138,7 +138,7 @@ def calculate_score(wm: WorldModel, next_self_pos: Vector2D, left_angle: AngleDe pos_count += 1 if our_ball: - if p.side() == wm.our_side() and (p.pos().x() > wm.ball().pos().x() - 10 or p.pos().x() > 30): + if p.side() == wm.our_side() and (p._pos.x() > wm.ball()._pos.x() - 10 or p._pos.x() > 30): pos_count *=2 base_val = pos_count**2 diff --git a/lib/action/neck_turn_to_ball.py b/lib/action/neck_turn_to_ball.py index 94d188c0..67bf5514 100644 --- a/lib/action/neck_turn_to_ball.py +++ b/lib/action/neck_turn_to_ball.py @@ -61,8 +61,8 @@ def execute(self, agent: 'PlayerAgent'): view_half = max(0, next_view_width*0.5 - 20) if (len(wm.opponents_from_self()) >= 11 - and (wm.ball().pos().x() > 0 - or wm.ball().pos().abs_y() > SP.pitch_half_width() - 8 + and (wm.ball()._pos.x() > 0 + or wm.ball()._pos.abs_y() > SP.pitch_half_width() - 8 or not opp or opp.dist_from_ball() > 3)): best_angle = NeckScanPlayers.INVALID_ANGLE diff --git a/lib/action/scan_field.py b/lib/action/scan_field.py index f8b286e7..c8e934eb 100644 --- a/lib/action/scan_field.py +++ b/lib/action/scan_field.py @@ -38,8 +38,8 @@ def find_ball(self, agent: 'PlayerAgent'): if agent.effector().queued_next_view_width() is not ViewWidth.WIDE: agent.set_view_action(ViewWide()) - my_next = wm.self().pos() + wm.self().vel() - face_angle = (wm.ball().seen_pos() - my_next).th() if wm.ball().seen_pos().is_valid() else (my_next*-1).th() + my_next = wm.self()._pos + wm.self()._vel + face_angle = (wm.ball()._seen_pos - my_next).th() if wm.ball()._seen_pos.is_valid() else (my_next*-1).th() search_flag = wm.ball().lost_count() //3 if search_flag%2==1: diff --git a/lib/action/smart_kick.py b/lib/action/smart_kick.py index 35895ad7..81e25a67 100644 --- a/lib/action/smart_kick.py +++ b/lib/action/smart_kick.py @@ -67,14 +67,14 @@ def execute(self, agent: 'PlayerAgent'): if ans[0]: self._sequence = ans[1] if self._sequence.speed_ >= first_speed_thr: # double check - vel = self._sequence.pos_list_[0] - wm.ball().pos() - kick_accel = vel - wm.ball().vel() + vel = self._sequence.pos_list_[0] - wm.ball()._pos + kick_accel = vel - wm.ball()._vel if SmartKick.debug_print_DEBUG: - log.os_log().debug(f"Kick Vel : {vel}, Kick Power : {kick_accel.r() / wm.self().kick_rate()}, Kick Angle : {kick_accel.th() - wm.self().body()}") - log.sw_log().kick().add_text(f"Kick Vel : {vel}, Kick Power : {kick_accel.r() / wm.self().kick_rate()}, Kick Angle : {kick_accel.th() - wm.self().body()}") + log.os_log().debug(f"Kick Vel : {vel}, Kick Power : {kick_accel.r() / wm.self().kick_rate()}, Kick Angle : {kick_accel.th() - wm.self()._body}") + log.sw_log().kick().add_text(f"Kick Vel : {vel}, Kick Power : {kick_accel.r() / wm.self().kick_rate()}, Kick Angle : {kick_accel.th() - wm.self()._body}") agent.do_kick(kick_accel.r() / wm.self().kick_rate(), - kick_accel.th() - wm.self().body()) + kick_accel.th() - wm.self()._body) if SmartKick.debug_print_DEBUG: log.os_log().debug(f"----------------#### Player Number {wm.self().unum()} 'DO_KICK'ed in SmartKick at Time: {wm.time().cycle()} ####----------------") log.sw_log().kick().add_text(f"----------------#### Player Number {wm.self().unum()} 'DO_KICK'ed in SmartKick at Time: {wm.time().cycle()} ####----------------") diff --git a/lib/action/stop_ball.py b/lib/action/stop_ball.py index 303a2468..919c431d 100644 --- a/lib/action/stop_ball.py +++ b/lib/action/stop_ball.py @@ -39,11 +39,11 @@ def execute(self, agent: 'PlayerAgent'): if not wm.self().is_kickable(): return False if not wm.ball().vel_valid(): # Always true until NFS nice :) - required_accel = wm.self().vel() - (wm.self().pos() - wm.ball().pos()) + required_accel = wm.self()._vel - (wm.self()._pos - wm.ball()._pos) kick_power = required_accel.r() / wm.self().kick_rate() kick_power *= 0.5 agent.do_kick(min(kick_power, ServerParam.i().max_power()), - required_accel.th() - wm.self().body()) + required_accel.th() - wm.self()._body) return True self._accel_radius = 0.0 @@ -59,7 +59,7 @@ def execute(self, agent: 'PlayerAgent'): # kick_power = min(kick_power, i.maxPower()) return agent.do_kick(kick_power, - self._accel_angle - wm.self().body()) + self._accel_angle - wm.self()._body) def calcAccel(self, agent): @@ -74,13 +74,13 @@ def calcAccel(self, agent): if target_dist > wm.self().player_type().kickable_area() - 0.1: target_dist = wm.self().player_type().kickable_area() - 0.1 - target_rel = wm.self().pos() - wm.ball().pos() + target_rel = wm.self()._pos - wm.ball()._pos target_rel.set_length(target_dist) required_accel = wm.self().vel() required_accel += target_rel # target relative to current - required_accel -= wm.self().pos() - wm.ball().pos() # vel = pos diff - required_accel -= wm.ball().vel() # required accel + required_accel -= wm.self()._pos - wm.ball()._pos # vel = pos diff + required_accel -= wm.ball()._vel # required accel self._accel_radius = required_accel.r() @@ -99,8 +99,8 @@ def calcAccel(self, agent): # keep the ball as much as possible near the best point next_ball_to_self = wm.self().vel() - next_ball_to_self -= wm.self().pos() - wm.ball().pos() - next_ball_to_self -= wm.ball().vel() + next_ball_to_self -= wm.self()._pos - wm.ball()._pos + next_ball_to_self -= wm.ball()._vel keep_dist = wm.self().player_type().player_size() + wm.self().player_type().kickable_margin() * 0.4 diff --git a/lib/action/turn_to_point.py b/lib/action/turn_to_point.py index 10623e57..dac2cd42 100644 --- a/lib/action/turn_to_point.py +++ b/lib/action/turn_to_point.py @@ -15,7 +15,7 @@ def execute(self, agent: 'PlayerAgent'): return agent.do_turn(60) my_point = self_player.inertia_point(self._cycle) - target_rel_angle = (self._point - my_point).th() - self_player.body() + target_rel_angle = (self._point - my_point).th() - self_player._body agent.do_turn(target_rel_angle) if target_rel_angle.abs() < 1: diff --git a/lib/messenger/messenger.py b/lib/messenger/messenger.py index 8a6be96a..37b42812 100644 --- a/lib/messenger/messenger.py +++ b/lib/messenger/messenger.py @@ -14,7 +14,7 @@ class Messenger: - DEBUG = True + DEBUG = False class Types(Enum): BALL = 'b' diff --git a/lib/player/localizer.py b/lib/player/localizer.py index 97fa666c..cb1dd99a 100644 --- a/lib/player/localizer.py +++ b/lib/player/localizer.py @@ -17,7 +17,7 @@ class Localizer: - DEBUG = True + DEBUG = False class PlayerT: def __init__(self) -> None: self.side_: SideID = SideID.NEUTRAL diff --git a/lib/player/object.py b/lib/player/object.py index a9d5e023..740761d2 100644 --- a/lib/player/object.py +++ b/lib/player/object.py @@ -7,22 +7,34 @@ def __init__(self): self._pos_error = Vector2D(0, 0) self._pos_count: int = 1000 self._possible_poses: list[Vector2D] = [] + self._pos_r: float = 0 + self._pos_th: AngleDeg = AngleDeg(0) self._seen_pos: Vector2D = Vector2D.invalid() self._seen_pos_count: int = 1000 + self._seen_pos_r: float = 0 + self._seen_pos_th: AngleDeg = AngleDeg(0) self._heard_pos: Vector2D = Vector2D.invalid() self._heard_pos_count: int = 1000 + self._heard_pos_r: float = 0 + self._heard_pos_th: AngleDeg = AngleDeg(0) self._vel = Vector2D.invalid() self._vel_error = Vector2D(0, 0) self._vel_count: int = 1000 - + self._vel_r: float = 0 + self._vel_th: AngleDeg = AngleDeg(0) + self._seen_vel: Vector2D = Vector2D.invalid() self._seen_vel_count: int = 1000 + self._seen_vel_r: float = 0 + self._seen_vel_th: AngleDeg = AngleDeg(0) self._heard_vel: Vector2D = Vector2D.invalid() self._heard_vel_count: int = 100 + self._heard_vel_r: float = 0 + self._heard_vel_th: AngleDeg = AngleDeg(0) self._rpos = Vector2D.invalid() self._rpos_error = Vector2D(0, 0) @@ -150,6 +162,20 @@ def update_more_with_full_state(self, wm: 'WorldModel'): self._dist_from_ball: float = (wm.ball().pos() - self.pos()) self._angle_from_ball: AngleDeg = (wm.ball().pos() - self.pos()).th() + def _update_helpers(self): + self._pos_th = self._pos.th() + self._vel_th = self._vel.th() + self._seen_pos_th = self._seen_pos.th() + self._seen_vel_th = self._seen_vel.th() + self._heard_pos_th = self._heard_pos.th() + self._heard_vel_th = self._heard_vel.th() + self._pos_r = self._pos.r() + self._vel_r = self._vel.r() + self._seen_pos_r = self._seen_pos.r() + self._seen_vel_r = self._seen_vel.r() + self._heard_pos_r = self._heard_pos.r() + self._heard_vel_r = self._heard_vel.r() + def _update_rpos(self, wm): self._rpos: Vector2D = self._pos - wm.self().pos() diff --git a/lib/player/object_ball.py b/lib/player/object_ball.py index ce7feb1d..0f21efc0 100644 --- a/lib/player/object_ball.py +++ b/lib/player/object_ball.py @@ -16,7 +16,7 @@ class BallObject(Object): - DEBUG = True + DEBUG = False def __init__(self, string=None): super().__init__() @@ -126,6 +126,9 @@ def update_by_last_cycle(self, act: 'ActionEffector', game_mode: GameMode): self._seen_vel_count = min(1000, self._seen_vel_count + 1) self._heard_vel_count = min(1000, self._heard_vel_count + 1) self._lost_count = min(1000, self._lost_count + 1) + + # at end + self._update_helpers() def update_only_vel(self, vel: Vector2D, vel_err: Vector2D, vel_count:int): self._vel = vel.copy() diff --git a/lib/player/object_player.py b/lib/player/object_player.py index e6a069ea..68f6d968 100644 --- a/lib/player/object_player.py +++ b/lib/player/object_player.py @@ -15,7 +15,7 @@ class PlayerObject(Object): - DEBUG = True + DEBUG = False def __init__(self, side: SideID = None, player: Localizer.PlayerT = None): super().__init__() @@ -217,6 +217,9 @@ def update_by_last_cycle(self): self._pointto_count = min(1000, self._pointto_count + 1) # self._kicking = min(1000, self._kicking + 1) self._tackle_count = min(1000, self._tackle_count + 1) + + # at end + self._update_helpers() def forgot(self): self._pos_count = 1000 diff --git a/lib/player/object_self.py b/lib/player/object_self.py index 0b24bdc4..c0fbefe2 100644 --- a/lib/player/object_self.py +++ b/lib/player/object_self.py @@ -17,7 +17,7 @@ class SelfObject(PlayerObject): FACE_COUNT_THR = 5 - DEBUG = True + DEBUG = False def __init__(self, player: PlayerObject = None): super().__init__() @@ -187,6 +187,9 @@ def update_by_last_cycle(self, act: ActionEffector, current_time: GameTime): self._collides_with_ball = False self._collides_with_player = False self._collides_with_post = False + + # at end + self._update_helpers() def update_angle_by_see(self, face: float, angle_face_error, current_time: GameTime): self._time = current_time.copy() @@ -356,6 +359,9 @@ def update_self_after_sense_body(self, sense_body: SenseBodyParser, act: ActionE self._change_focus_count = sense_body.change_focus_count() self._focus_point_dist = sense_body.focus_point_dist() self._focus_point_dir = AngleDeg(sense_body.focus_point_dir()) + + # at end + self._update_helpers() def set_pointto(self,point: Vector2D, done_time: GameTime): self._pointto_pos = point.copy() diff --git a/lib/player/player_agent.py b/lib/player/player_agent.py index fcef44b6..bd6bbab6 100644 --- a/lib/player/player_agent.py +++ b/lib/player/player_agent.py @@ -29,7 +29,7 @@ from lib.parser.parser_message_fullstate_world import FullStateWorldMessageParser -DEBUG = True +DEBUG = False def get_time_msec(): @@ -505,6 +505,10 @@ def do_attentionto(self, side: SideID, unum: int): def do_attentionto_off(self): self._last_body_command.append(self._effector.set_attentionto_off()) return True + + def do_pointto_off(self): + self._last_body_command.append(self._effector.set_pointto_off()) + return True if team_config.WORLD_IS_REAL_WORLD: def world(self): diff --git a/lib/player/world_model.py b/lib/player/world_model.py index 0877bdca..69de6881 100644 --- a/lib/player/world_model.py +++ b/lib/player/world_model.py @@ -19,7 +19,7 @@ from typing import List -DEBUG=True +DEBUG=False from typing import TYPE_CHECKING @@ -43,7 +43,7 @@ def player_valid_check(p: PlayerObject): return p.pos_valid() class WorldModel: - DEBUG = True + DEBUG = False DIR_CONF_DIVS = 72 DIR_STEP = 360. / DIR_CONF_DIVS @@ -598,12 +598,15 @@ def localize_self(self, # my_pos: Vector2D = self._localizer.localize_self_simple(see, angle_face) my_pos, my_pos_err, my_possible_posses = self._localizer.localize_self(see, self.self().view_width(), angle_face, angle_face_error) if my_pos is None: + self.self()._update_helpers() return False if reverse_side: my_pos *= -1.0 if my_pos.is_valid(): self.self().update_pos_by_see(my_pos, my_pos_err, my_possible_posses, team_angle_face, angle_face_error, current_time) + + self.self()._update_helpers() def localize_ball(self, see: SeeParser, act: 'ActionEffector'): SP = ServerParam.i() @@ -629,6 +632,7 @@ def localize_ball(self, see: SeeParser, act: 'ActionEffector'): tvel_err *= SP.ball_decay() self._ball.update_only_vel(tvel, tvel_err, 1) self._ball.update_only_relative_pos(rpos, rpos_err) + self._ball._update_helpers() return pos = self.self().pos() + rpos @@ -677,6 +681,8 @@ def localize_ball(self, see: SeeParser, act: 'ActionEffector'): gvel, vel_err, vel_count) else: self._ball.update_pos(pos, pos_err, self.self().pos_count(), rpos, rpos_err) + + self._ball._update_helpers() def their_side(self): return SideID.LEFT if self._our_side is SideID.RIGHT else SideID.RIGHT @@ -963,6 +969,9 @@ def localize_players(self, see: SeeParser): self._teammates = list(filter(player_valid_check, self._teammates)) self._opponents = list(filter(player_valid_check, self._opponents)) log.os_log().debug(f'opp len {len(self._opponents)} E') + + for p in self._teammates + self._opponents + self._unknown_players: + p._update_helpers() def update_player_type(self): for p in self._teammates: @@ -1353,6 +1362,7 @@ def update_by_full_state_message(self, parser: FullStateWorldMessageParser): for o in [self.ball()] + self._teammates + self._opponents + self._unknown_players: o.update_more_with_full_state(self) + o._update_helpers() def update_just_before_decision(self, act: 'ActionEffector', current_time: GameTime): self._set_play_count += 1 @@ -1379,7 +1389,8 @@ def update_just_before_decision(self, act: 'ActionEffector', current_time: GameT self.intercept_table().self_reach_cycle(), self.intercept_table().teammate_reach_cycle(), self.intercept_table().opponent_reach_cycle()) - + for o in self._teammates + self._opponents + self._unknown_players + [self._ball]: + o._update_helpers() if DEBUG: log.sw_log().world().add_text('===After processing see message===') log.sw_log().world().add_text(f'self.kickrate={self.self().kick_rate()}') diff --git a/main.py b/main.py index 2cc12078..ad44f7f7 100755 --- a/main.py +++ b/main.py @@ -8,13 +8,13 @@ players = [] -goalie = mp.Process(target=main_p.main, args=(1,True)) +goalie = mp.Process(target=main_p.main) goalie.start() players.append(goalie) for i in range(2,12): - proc = mp.Process(target=main_p.main, args=(i,False)) + proc = mp.Process(target=main_p.main) proc.start() players.append(proc) sleep(0.25) diff --git a/start.sh b/start.sh index 57635c68..4adcc988 100755 --- a/start.sh +++ b/start.sh @@ -13,4 +13,4 @@ while [ $i -le 11 ] ; do done sleep 2 -python coach_main.py ${1+"$@"} +python base/main_coach.py ${1+"$@"}