def do_get_puck_actions(self, env):
        if self.its_dangerous(env):
            hockeyist_with_puck = shortcuts.hockeyist_with_puck(env)
            if hockeyist_with_puck is not None:
                if shortcuts.can_strike_unit(env, hockeyist_with_puck):
                    env.move.action = ActionType.STRIKE
                    return

        env.move.speed_up = 1.0
        hwp = shortcuts.hockeyist_with_puck(env)
        if hwp is not None:
            basic_actions.turn_to_unit(env, hwp)
        else:
            basic_actions.turn_to_unit(env, env.world.puck)

        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.0:
                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

        if hwp is not None and shortcuts.can_strike_unit(env, hwp):
            env.move.action = ActionType.STRIKE
            return
    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 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 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 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 take_pass(self, env, gstrategy):
     basic_actions.turn_to_unit(env, env.world.puck)