Пример #1
0
        def count_strike_point(env):
            opponent_player = shortcuts.opponent_player(env)
            # uu = Unit(0,0,0,opponent_player.net_front, env.game.goal_net_top + env.game.goal_net_height, 0,0,0,0)
            # geometry.rad_to_degree(uu.get_angle_to(env.game.rink_left / 2. + env.game.rink_right /2. , env.game.rink_top))

            # import ipdb; ipdb.set_trace()
            return geometry.ray_interval_intersection_v2(
                geometry.Point(opponent_player.net_front, env.game.goal_net_top + env.game.goal_net_height),
                geometry.Point(math.cos(geometry.degree_to_rad(-150)), math.sin(geometry.degree_to_rad(-150))),
                geometry.Point(0, env.game.goal_net_top - 100),
                geometry.Point(world.width, env.game.goal_net_top - 100),
            )
Пример #2
0
    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)
Пример #3
0
def fast_move_to_point_backward(env, point):
    distance = env.me.get_distance_to_unit(point)
    mirrow_point = geometry.Point(
        2 * env.me.x - point.x,
        2 * env.me.y - point.y
    )
    angle = env.me.get_angle_to_unit(mirrow_point)

    if abs(angle) > geometry.degree_to_rad(1):
        env.move.turn = angle
        return

    v0 = geometry.vector_abs(env.me.speed_x, env.me.speed_y)
    vn = 0
    a = -env.game.hockeyist_speed_up_factor
    n = prediction.count_n(v0, a, vn)

    if n is None:
        env.move.speed_up = -1.0
        return

    n = round(n) + 1
    x0 = 0.
    xn = prediction.count_xn(x0, v0, a, n)

    if xn > distance:
        env.move.speed_up = 1.0
    else:
        env.move.speed_up = -1.0
Пример #4
0
    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 do(self, env):
        angle = env.me.get_angle_to_unit(self.point)
        if abs(angle) <= geometry.degree_to_rad(0.1):
            self.done = True
            print 'tick = ', env.world.tick, 'TurnToPoint done'
            return

        env.move.turn = angle
Пример #6
0
 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
Пример #7
0
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 do(self, env):
        distance = env.me.get_distance_to_unit(self.point)
        angle = env.me.get_angle_to_unit(self.point)

        if distance < 2:
            self.done = True
            speed_abs = geometry.vector_abs(env.me.speed_x, env.me.speed_y)
            print (
                'tick = ', env.world.tick,
                'MoveToPoint done',
                'x = ', env.me.x,
                'y = ', env.me.y,
                'speed abs = ', speed_abs
            )
            return

        if abs(angle) > geometry.degree_to_rad(1):
            env.move.turn = angle
            return

        v0 = geometry.vector_abs(env.me.speed_x, env.me.speed_y)
        vn = 0
        a = -env.game.hockeyist_speed_down_factor
        n = prediction.count_n(v0, a, vn)

        if n is None:
            env.move.speed_up = 1.0
            # print 'tick = ', env.world.tick, 'speed = 1. n is None'
            return

        n = round(n) + 1
        x0 = 0.
        xn = prediction.count_xn(x0, v0, a, n)

        # print (
        #     'v0 = ', v0,
        #     'n =', n,
        #     'xn =', xn,
        #     'dist = ', distance
        # )
        # import ipdb; ipdb.set_trace()
        if xn > distance:
            # print 'tick = ', env.world.tick, 'speed = -1.'
            env.move.speed_up = -1.0
        else:
            # print 'tick = ', env.world.tick, 'speed = 1.'
            env.move.speed_up = 1.0
Пример #9
0
    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)
Пример #10
0
    def move(self, me, world, game, move):
        if me.teammate_index != 0:
            return

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

        if world.tick == 0:
            self.expected_angle = me.angle

        move.turn = geometry.degree_to_rad(10)
        print (
            'tick = ', world.tick,
            'angle = ', geometry.rad_to_degree(me.angle),
            'expected_angle =', geometry.rad_to_degree(self.expected_angle),
            'diff = ', geometry.rad_to_degree(abs(self.expected_angle - me.angle)),
            'angular_speed = ', geometry.rad_to_degree(me.angular_speed)
        )

        self.expected_angle = predict_andle(env)


        if world.tick >= 20:
            import ipdb; ipdb.set_trace()
Пример #11
0
def count_optimistic_attack_polygons(env, player):
    return [
        count_attack_polygon(env, player, is_down,
            geometry.degree_to_rad(27), geometry.degree_to_rad(53), 0, 0)
        for is_down in (False, True)
    ]
Пример #12
0
def count_attack_polygon(
    env, player, is_down, angle_min, angle_max, rink_margin, middle_margin):

    is_left = shortcuts.player_left(env, player)
    left_sign = shortcuts.player_left_sign(env, player)
    left_sign = 1 if is_left else -1

    # down_sign = 1 - нижняя половина
    down_sign = 1 if is_down else -1.

    if is_down:
        corner_y = player.net_top
    else:
        corner_y = player.net_bottom

    corner = geometry.Point(
        player.net_front,
        corner_y)

    # attack_y_min - линия ближе к границе
    # attack_y_max - линия ближе к воротам
    if is_down:
        attack_y_min = env.game.rink_bottom - rink_margin
    else:
        attack_y_min = env.game.rink_top + rink_margin
    if is_down:
        attack_y_max = player.net_bottom - shortcuts.goalie_radius() - middle_margin
    else:
        attack_y_max = player.net_top + shortcuts.goalie_radius() + middle_margin

    attack_x_min = env.game.rink_left
    attack_x_max = env.game.rink_right

    angle_sign = left_sign * down_sign
    if is_left:
        angle_shift = 0.
    else:
        angle_shift = geometry.degree_to_rad(180)

    p1 = geometry.ray_interval_intersection_v2(
        corner,
        geometry.angle_vector(angle_sign * angle_min + angle_shift, 1),
        geometry.Point(attack_x_min, attack_y_max),
        geometry.Point(attack_x_max, attack_y_max)
    )
    p2 = geometry.ray_interval_intersection_v2(
        corner,
        geometry.angle_vector(angle_sign * angle_min + angle_shift, 1),
        geometry.Point(attack_x_min, attack_y_min),
        geometry.Point(attack_x_max, attack_y_min)
    )
    p3 = geometry.ray_interval_intersection_v2(
        corner,
        geometry.angle_vector(angle_sign * angle_max + angle_shift, 1),
        geometry.Point(attack_x_min, attack_y_min),
        geometry.Point(attack_x_max, attack_y_min)
    )
    p4 = geometry.ray_interval_intersection_v2(
        corner,
        geometry.angle_vector(angle_sign * angle_max + angle_shift, 1),
        geometry.Point(attack_x_min, attack_y_max),
        geometry.Point(attack_x_max, attack_y_max)
    )
    return geometry.Polygon([p1, p2, p3, p4])
Пример #13
0
def count_cautious_attack_polygons(env, player):
    return [
        count_attack_polygon(env, player, is_down,
            geometry.degree_to_rad(27), geometry.degree_to_rad(60), 0, 100)
        for is_down in (False, True)
    ]
Пример #14
0
def count_dead_polygons(env, player):
    return [
        count_attack_polygon(env, player, is_down,
            geometry.degree_to_rad(65), geometry.degree_to_rad(90), 0, 0)
        for is_down in (False, True)
    ]
Пример #15
0
def count_target_up_attack_polygon(env, player):
    return count_attack_polygon(
        env, player, False,
        geometry.degree_to_rad(35), geometry.degree_to_rad(50), 50, -100
    )
Пример #16
0
 def move(self, me, world, game, move):
     angle = me.get_angle_to(self.target_x, self.target_y)
     move.turn = angle
     if abs(angle) < geometry.degree_to_rad(1):
         move.speed_up = 1.
Пример #17
0
def turned_to_unit(env, unit, eps=geometry.degree_to_rad(1)):
    angle = env.me.get_angle_to_unit(unit)
    return abs(angle) < eps
Пример #18
0
def count_attack_polygons(env, player):
    is_left = shortcuts.player_left(env, player)
    left_sign = shortcuts.player_left_sign(env, player)
    left_sign = 1 if is_left else -1

    angle_min = geometry.degree_to_rad(37)
    angle_max = geometry.degree_to_rad(53)

    polygons = []
    # down_sign = 1 - нижняя половина
    for down_sign in (-1, 1):
        is_down = down_sign > 0

        if is_down:
            corner_y = player.net_top
        else:
            corner_y = player.net_bottom

        corner = geometry.Point(
            player.net_front,
            corner_y)

        # attack_y_min - линия ближе к границе
        # attack_y_max - линия ближе к воротам
        if is_down:
            attack_y_min = env.game.rink_bottom - 30
        else:
            attack_y_min = env.game.rink_top + 30
        if is_down:
            attack_y_max = player.net_bottom - shortcuts.goalie_radius() - 30
        else:
            attack_y_max = player.net_top + shortcuts.goalie_radius() + 30

        attack_x_min = env.game.rink_left
        attack_x_max = env.game.rink_right

        angle_sign = left_sign * down_sign
        if is_left:
            angle_shift = 0.
        else:
            angle_shift = geometry.degree_to_rad(180)

        p1 = geometry.ray_interval_intersection_v2(
            corner,
            geometry.angle_vector(angle_sign * angle_min + angle_shift, 1),
            geometry.Point(attack_x_min, attack_y_max),
            geometry.Point(attack_x_max, attack_y_max)
        )
        p2 = geometry.ray_interval_intersection_v2(
            corner,
            geometry.angle_vector(angle_sign * angle_min + angle_shift, 1),
            geometry.Point(attack_x_min, attack_y_min),
            geometry.Point(attack_x_max, attack_y_min)
        )
        p3 = geometry.ray_interval_intersection_v2(
            corner,
            geometry.angle_vector(angle_sign * angle_max + angle_shift, 1),
            geometry.Point(attack_x_min, attack_y_min),
            geometry.Point(attack_x_max, attack_y_min)
        )
        p4 = geometry.ray_interval_intersection_v2(
            corner,
            geometry.angle_vector(angle_sign * angle_max + angle_shift, 1),
            geometry.Point(attack_x_min, attack_y_max),
            geometry.Point(attack_x_max, attack_y_max)
        )
        polygons.append(geometry.Polygon([p1, p2, p3, p4]))

    return polygons