def count_defence_point(env):
    im_left_sign = shortcuts.im_left_sign(env)
    my_player = shortcuts.my_player(env)
    return geometry.Point(
        my_player.net_front + im_left_sign * 90,
        shortcuts.field_center(env).y
    )
 def __init__(self, env):
     op = shortcuts.opponent_player(env)
     mp = shortcuts.my_player(env)
     self.attack_polygons = experiments.count_optimistic_attack_polygons(
         env, op)
     self.target_polygons = [
         experiments.count_target_up_attack_polygon(env, op),
         experiments.count_target_down_attack_polygon(env, op),
     ]
     self.defence_point = experiments.count_defence_point(env)
     self.weak_polygons = experiments.count_cautious_attack_polygons(
         env, mp)
     self.dead_polygons = experiments.count_dead_polygons(env, op)
    def move(self, me, world, game, move):

        env = environment.Environment(me, world, game, move)

        if world.tick == 0:
            op = shortcuts.opponent_player(env)
            mp = shortcuts.my_player(env)
            self.attack_polygons = experiments.count_optimistic_attack_polygons(env, op)
            self.target_polygons = [
                experiments.count_target_up_attack_polygon(env, op),
                experiments.count_target_down_attack_polygon(env, op),
            ]
            self.defence_point = experiments.count_defence_point(env)
            self.weak_polygons = experiments.count_cautious_attack_polygons(env, mp)
            self.dead_polygons = experiments.count_dead_polygons(env, op)

            self.last_puck_owner_player_id = None

        self.save_last_puck_owner(env)
        self.save_start_game_tick(env)

        if env.me.state == HockeyistState.SWINGING:
            if self.swing_condition(env):
                env.move.action = ActionType.SWING

            if self.strike_condition(env):
                env.move.action = ActionType.STRIKE

            return

        hockeyist_with_puck = shortcuts.hockeyist_with_puck(env)
        my_nearest_hockeyist = min(
            shortcuts.my_field_hockeyists(env), key=lambda h: assessments.ticks_to_reach_point(env, h, env.world.puck)
        )
        if hockeyist_with_puck is None or hockeyist_with_puck.player_id != env.me.player_id:
            if my_nearest_hockeyist.id == me.id:
                self.do_get_puck_actions(env)
            else:
                self.do_protect_goal_actions(env)
        elif hockeyist_with_puck.player_id == env.me.player_id:
            if hockeyist_with_puck.id == env.me.id:
                self.attack_with_puck(env)
            else:
                self.do_protect_goal_actions(env)
def puck_is_heading_to_my_net(env):
    player = shortcuts.my_player(env)
    pbegin = geometry.Point(
        player.net_front,
        env.game.rink_top
    )
    pend = geometry.Point(
        player.net_front,
        env.game.rink_bottom
    )
    intersection = geometry.ray_interval_intersection_v2(
        env.world.puck,
        geometry.Point(
            env.world.puck.speed_x,
            env.world.puck.speed_y
        ),
        pbegin,
        pend
    )
    if intersection is None:
        return False

    angle = geometry.ray_ray_angle(
        env.world.puck,
        intersection,
        geometry.Point(
            player.net_front,
            env.game.rink_top
        ))

    if abs(geometry.degree_to_rad(90) - angle) < geometry.degree_to_rad(20):
        return False

    if intersection.y < player.net_top:
        return (player.net_top - intersection.y) < 10
    if intersection.y > player.net_bottom:
        return (intersection.y - player.net_bottom) < 10
    return abs(intersection.y - player.net_top) < 50 or abs(intersection.y - player.net_bottom) < 50
def count_weak_points(env):
    return _count_player_weak_points(
        env,
        shortcuts.my_player(env)
    )