def can_run(self, env):
     if abs(env.world.puck.y - shortcuts.rink_center(env).y) < 130:
         return False
     for oh in shortcuts.opponent_field_hockeyists(env):
         if geometry.distance(env.me, oh) < 150:
             return False
     return True
    def do_protect_goal_actions(self, env, gstrategy):
        if shortcuts.can_take_puck(env):
            puck_abs_speed = geometry.vector_abs(env.world.puck.speed_x, env.world.puck.speed_y)
            if shortcuts.take_puck_probability(env, puck_abs_speed) >= 1.:
                env.move.action = ActionType.TAKE_PUCK
                return

            if not assessments.puck_is_heading_to_my_net(env):
                env.move.action = ActionType.TAKE_PUCK
                return

        if shortcuts.can_strike_unit(env, env.world.puck):
            env.move.action = ActionType.STRIKE
            return

        for oh in shortcuts.opponent_field_hockeyists(env):
            if shortcuts.can_strike_unit(env, oh):
                env.move.action = ActionType.STRIKE
                return

        if self.its_dangerous(env) and env.me.get_distance_to_unit(self.precount.defence_point) < 100:
            basic_actions.turn_to_unit(env, env.world.puck)
            if geometry.distance(self.precount.defence_point, env.world.puck) <= 200:
                if basic_actions.turned_to_unit(env, env.world.puck):
                    env.move.speed_up = 1.
            return

        speed_abs = geometry.vector_abs(env.me.speed_x, env.me.speed_y)
        if env.me.get_distance_to_unit(self.precount.defence_point) >= 20:
            experiments.fast_move_to_point(env, self.precount.defence_point)
        elif speed_abs > 0.01:
            experiments.do_stop(env)
        else:
            basic_actions.turn_to_unit(env, env.world.puck)
def stick_sectors(env):
    for h in shortcuts.my_field_hockeyists(env) + shortcuts.opponent_field_hockeyists(env):
        p1 = geometry.point_plus_vector(
            h, h.angle + env.game.stick_sector / 2., env.game.stick_length)
        p2 = geometry.point_plus_vector(
            h, h.angle - env.game.stick_sector / 2., env.game.stick_length)
        draw.line(h, p1)
        draw.line(h, p2)
    def __init__(self, env):
        self.env = env
        self.id_to_fh_free = {}
        self.tick_to_puck = {0: env.world.puck}

        fhs = shortcuts.my_field_hockeyists(self.env) + shortcuts.opponent_field_hockeyists(self.env)
        for h in fhs:
            self.id_to_fh_free[h.id] = {0: h}
def someone_can_reach_me_after_ticks(env, ticks):
    opponent_hockeyists = shortcuts.opponent_field_hockeyists(env)
    for h in opponent_hockeyists:
        for t in range(ticks + 1):
            future_h = prediction.next_hockeyist_position(env, h, t)
            if shortcuts.hockeyist_can_strike_unit(env, future_h, env.me):
                return True
            if shortcuts.hockeyist_can_take_puck(env, future_h):
                return True
    return False
 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
    def opponent_protect_goal(self, env, goal_point):

        for h in shortcuts.opponent_field_hockeyists(env):
            distance = geometry.ray_point_distance(
                env.world.puck,
                geometry.diff(env.world.puck, goal_point),
                h
            )
            if distance <= h.radius:
                return True
        return False
    def attack_without_puck(self, env):
        nearest_opponent = shortcuts.nearest_unit(
            shortcuts.opponent_field_hockeyists(env), env.me)

        distance = env.me.get_distance_to_unit(nearest_opponent)
        angle = env.me.get_angle_to_unit(nearest_opponent)
        if distance > env.game.stick_length:
            env.move.speed_up = 1.0
        env.move.turn = angle

        if shortcuts.can_strike_unit(env, nearest_opponent):
            env.move.action = ActionType.STRIKE
    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 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 count_free_motion_next_tick(env):
    new_env = copy_env(env)

    def update_puck(new_puck, puck):
        new_puck.x = count_xn(puck.x, puck.speed_x, 0, 1, k=puck_friction_factor())
        new_puck.y = count_xn(puck.y, puck.speed_y, 0, 1, k=puck_friction_factor())
        new_puck.speed_x = count_vn(puck.speed_x, 0, 1, k=puck_friction_factor())
        new_puck.speed_y = count_vn(puck.speed_y, 0, 1, k=puck_friction_factor())

    def update_hockeyist(new_h, h):
        new_h.x = count_xn(h.x, h.speed_x, 0, 1, k=friction_factor())
        new_h.y = count_xn(h.y, h.speed_y, 0, 1, k=friction_factor())
        new_h.speed_x = count_vn(h.speed_x, 0, 1, k=friction_factor())
        new_h.speed_y = count_vn(h.speed_y, 0, 1, k=friction_factor())

    update_puck(new_env.world.puck, env.world.puck)

    for h in shortcuts.my_field_hockeyists(env) + shortcuts.opponent_field_hockeyists(env):
        new_h = filter(
            lambda nh: nh.id == h.id,
            new_env.world.hockeyists
        )[0]
        update_hockeyist(new_h, h)
    return new_env
def stick_circles(env):
    for h in shortcuts.my_field_hockeyists(env) + shortcuts.opponent_field_hockeyists(env):
        draw.circle(h, env.game.stick_length)
 def f(h):
     return min(
         geometry.distance(h, oh)
         for oh in shortcuts.opponent_field_hockeyists(env)
     )