def get_goal_point(env, puck):
    opponent_player = env.world.get_opponent_player()
    if opponent_player.net_back > shortcuts.rink_center(env).x:
        goal_x = opponent_player.net_front + 20
    else:
        goal_x = opponent_player.net_front - 20
    if puck.y < shortcuts.rink_center(env):
        goal_y = opponent_player.net_bottom
    else:
        goal_y = opponent_player.net_top
    return geometry.Point(goal_x, goal_y)
Esempio n. 2
0
 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
Esempio n. 3
0
 def save_start_game_tick(self, env):
     puck = env.world.puck
     if geometry.distance(puck, shortcuts.rink_center(env)) > 0.1:
         return
     puck_abs_speed = geometry.vector_abs(puck.speed_x, puck.speed_y)
     if puck_abs_speed > 0.1:
         return
     self.game_start_tick = env.world.tick
Esempio n. 4
0
def _count_player_weak_points(env, player):
    is_left = 1. if player.net_back < shortcuts.rink_center(env).x else -1.
    return [
        geometry.Point(
            player.net_front + is_left * env.game.goal_net_height * 1.5,
            env.game.goal_net_top - 50
        ),
        geometry.Point(
            player.net_front + is_left * env.game.goal_net_height * 1.5,
            env.game.goal_net_top + env.game.goal_net_height + 50
        )
    ]
def count_chances(env):
    radius = env.world.puck.radius
    total = 0
    hits = 0
    hits_in_area = 0
    hits_not_in_area = 0
    miss_in_area = 0
    miss_not_in_area = 0

    # polygon = experiments.count_puck_attack_area(env, shortcuts.opponent_player(env))

    res_str = ""
    for x in range(int(env.game.rink_left + radius), int(env.game.rink_right - radius), 5):
        for y in range(int(env.game.rink_top + radius), int(env.game.rink_bottom - radius), 5):

            if y > shortcuts.rink_center(env).y:
                continue

            puck = make_puck(env, x, y)
            goalie = goalie_by_puck(env, puck)
            hit = not prediction.goalie_can_save_straight(env, puck=puck, goalie=goalie)

            # in_area = geometry.point_in_convex_polygon(
            #     geometry.Point(x, y), polygon)
            in_area = True

            total += 1
            if hit:
                hits += 1
                res_str += "point {0} {1}\n".format(x, y)
            if hit and in_area:
                hits_in_area += 1
            if hit and not in_area:
                hits_not_in_area += 1
            if not hit and in_area:
                miss_in_area += 1
            if not hit and not in_area:
                miss_not_in_area += 1

    print "total", total
    print "hits", hits
    print "hits_in_area", hits_in_area
    print "hits_not_in_area", hits_not_in_area
    print "miss_in_area", miss_in_area
    print "miss_not_in_area", miss_not_in_area
    with open("draw_area", "w") as i:
        i.write(res_str)
def find_points(env, speed_abs, shift):

    # polygon = experiments.count_puck_attack_area(env, shortcuts.opponent_player(env))
    step = 5
    res_str = ''
    points = []
    for x in range(int(env.game.rink_left), int(env.game.rink_right), step):
        for y in range(int(env.game.rink_top), int(env.game.rink_bottom), step):

            if y > shortcuts.rink_center(env).y:
                continue

            puck = make_puck(env, x, y, speed_abs, shift)
            goalie = goalie_by_puck(env, puck)
            hit = not prediction.goalie_can_save_straight(
                env, puck=puck, goalie=goalie)

            if hit:
                res_str += 'point {0} {1}\n'.format(x, y)
                points.append(geometry.Point(x, y))

            # if hit and x > 1100:
            #     import ipdb; ipdb.set_trace()
            #     pass

    if not points:
        return None

    hull = shapely.geometry.MultiPoint([
        shapely.geometry.Point(p.x, p.y)
        for p in points
    ]).convex_hull

    if hull.type != 'Polygon':
        return None

    pol = geometry.Polygon([
        geometry.Point(c[0], c[1])
        for c in list(hull.exterior.coords)
    ])
    return pol
env = make_start_env_im_left()

pols = {}
optimistic_pols = {}
speed_abs = 15.
while speed_abs <= 20.:
    fp = find_points(env, speed_abs, 20)
    if fp is not None:
        pols[speed_abs] = fp
    fpo = find_points(env, speed_abs, 2)
    if fpo is not None:
        optimistic_pols[speed_abs] = fpo
    speed_abs += 0.5

up_right_pols = pols
rc = shortcuts.rink_center(env)

up_left_pols = {}
for k, v in up_right_pols.iteritems():
    up_left_pols[k] = geometry.Polygon([
        geometry.mirror_x(p, rc.x)
        for p in v.points
    ])

down_left_pols = {}
for k, v in up_right_pols.iteritems():
    down_left_pols[k] = geometry.Polygon([
        geometry.mirror_y(geometry.mirror_x(p, rc.x), rc.y)
        for p in v.points
    ])
Esempio n. 8
0
 def attack_without_puck(self, env, gstrategy):
     strike_point = gstrategy.strike_point
     strike_point = geometry.mirror_x(strike_point, shortcuts.rink_center(env).x)
     strike_point = geometry.mirror_y(strike_point, shortcuts.rink_center(env).y)
     experiments.fast_move_to_point_forward(env, strike_point)