def attack_with_puck(self, env): def f(point): nfc = shortcuts.net_front_center(env, shortcuts.opponent_player(env)) angles = [ min(geometry.degree_to_rad(110), geometry.ray_ray_angle(oh, env.me, point)) for oh in shortcuts.opponent_field_hockeyists(env) if geometry.distance(oh, nfc) > 300 ] ticks_to_reach_point = assessments.ticks_to_reach_point(env, env.me, point) if not angles: return -ticks_to_reach_point return geometry.rad_to_degree(min(angles)) - ticks_to_reach_point / 100 strike_point = algorithm.best_point_for_polynoms(self.target_polygons, f=f) if any(geometry.point_in_convex_polygon(env.me, p) for p in self.attack_polygons): goal_point = experiments.get_goal_point(env) basic_actions.turn_to_unit(env, goal_point) if basic_actions.turned_to_unit(env, goal_point, eps=geometry.degree_to_rad(1.0)): env.move.speed_up = 1.0 if self.swing_condition(env): env.move.action = ActionType.SWING if self.strike_condition(env): env.move.action = ActionType.STRIKE return if self.pass_condition(env, strike_point): self.do_pass(env) return experiments.fast_move_to_point_forward(env, strike_point)
def attack_with_puck(self, env): if any(geometry.point_in_convex_polygon(env.me, p) for p in self.attack_polygons): strike_point = env.me else: strike_point = algorithm.best_point_for_polynoms( self.attack_polygons, f=lambda p: -assessments.ticks_to_reach_point(env, env.me, p)) # strike_point = geometry.convex_polygons_nearest_point( # self.attack_polygons, env.me) if env.me.get_distance_to_unit(strike_point) >= 60: # print strike_point experiments.fast_move_to_point(env, strike_point) return goal_point = experiments.get_goal_point(env) basic_actions.turn_to_unit(env, goal_point) if basic_actions.turned_to_unit(env, goal_point, eps=geometry.degree_to_rad(1.0)): # if self.opponent_protect_goal(env, goal_point): # env.move.action = ActionType.SWING # else: # env.move.action = ActionType.STRIKE env.move.action = ActionType.SWING
def test_point_in_convex_polygon(self): polygon = geometry.Polygon([ geometry.Point(0, 0), geometry.Point(1, 0), geometry.Point(1, 1), geometry.Point(0, 1), ]) self.assertTrue(geometry.point_in_convex_polygon( geometry.Point(0.5, 0.5), polygon )) self.assertFalse(geometry.point_in_convex_polygon( geometry.Point(1.5, 0.5), polygon )) self.assertFalse(geometry.point_in_convex_polygon( geometry.Point(1.00001, 0.00001), polygon )) self.assertTrue(geometry.point_in_convex_polygon( geometry.Point(0.99999, 0.00001), polygon ))
def pass_condition(self, env, strike_point): if env.world.tick - self.history.game_start_tick <= 75: return True pass_taker = self.count_pass_taker(env) if geometry.distance(self.hwp, pass_taker) > 200: for oh in shortcuts.opponent_field_hockeyists(env): if geometry.interval_point_distance(self.hwp, strike_point, oh) < 60: return True if any(geometry.point_in_convex_polygon(self.hwp, p) for p in self.precount.dead_polygons): return True return False
def attack_with_puck(self, env, gstrategy): strike_point = gstrategy.strike_point if any(geometry.point_in_convex_polygon(env.me, p) for p in self.precount.attack_polygons): goal_point = experiments.get_goal_point(env) basic_actions.turn_to_unit(env, goal_point) if basic_actions.turned_to_unit(env, goal_point, eps=geometry.degree_to_rad(1.0)): env.move.speed_up = 1. if self.swing_condition(env): env.move.action = ActionType.SWING if self.strike_condition(env): env.move.action = ActionType.STRIKE return experiments.fast_move_to_point_forward(env, strike_point)
def pass_condition(self, env, strike_point): if env.world.tick - self.game_start_tick <= 75: return True collega = filter(lambda h: h.id != env.me.id, shortcuts.my_field_hockeyists(env))[0] net_center = shortcuts.net_front_center(env, shortcuts.opponent_player(env)) if geometry.distance(collega, env.me) > 200: for oh in shortcuts.opponent_field_hockeyists(env): # my_angle = geometry.ray_ray_angle(env.me, strike_point, net_center) # o_angle = geometry.ray_ray_angle(oh, strike_point, net_center) # my_distance = geometry.distance(env.me, strike_point) # o_distance = geometry.distance(oh, strike_point) # if my_angle > o_angle and my_distance > o_distance: # return True if geometry.interval_point_distance(env.me, strike_point, oh) < 60: return True if any(geometry.point_in_convex_polygon(env.me, p) for p in self.dead_polygons): return True return False
def its_dangerous(self, env): return ( any(geometry.point_in_convex_polygon(env.world.puck, p) for p in self.weak_polygons) or geometry.distance(env.world.puck, self.defence_point) < 120 )