def test(env): x, y = 950.975341797, 343.462585449 speed_x, speed_y = 15.5862091064, 13.4079335531 # x = shortcuts.opponent_player(env).net_front - env.game.goal_net_height # y = env.game.goal_net_top print "start puck", x, y # puck = make_puck(env, x, y) puck = make_puck(env, x, y, speed_x, speed_y) goalie = goalie_by_puck(env, puck) return prediction.goalie_can_save_straight(env, puck=puck, goalie=goalie)
def can_goal(env, hockeyist, player): if env.world.puck.owner_hockeyist_id != hockeyist.id: return False speed_abs = shortcuts.puck_speed_abs_after_strike(env, hockeyist) puck_after_strike = prediction.UnitShadow( env.world.puck.x, env.world.puck.y, speed_abs * math.cos(hockeyist.angle), speed_abs * math.sin(hockeyist.angle) ) return not prediction.goalie_can_save_straight(env, puck=puck_after_strike)
def strike_condition(self, env): if env.me.swing_ticks >= env.game.max_effective_swing_ticks: return True if env.me.state == HockeyistState.SWINGING: next_puck = prediction.next_puck_position(env) next_me = prediction.next_hockeyist_position(env, env.me, 1) # HARDCODE next_me.swing_ticks = min(20, env.me.swing_ticks + 1) after_strike = assessments.puck_after_strike(env, hockeyist=next_me, puck=next_puck) if prediction.goalie_can_save_straight(env, puck=after_strike): return True return False
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
def can_hit(env, x, y): puck = make_puck(env, x, y) goalie = goalie_by_puck(env, puck) return not prediction.goalie_can_save_straight(env, puck=puck, goalie=goalie)
def swing_condition(self, env): if self.can_run(env): return False puck = assessments.puck_after_strike(env) return not prediction.goalie_can_save_straight(env, puck=puck)
def move(self, me, world, game, move): if me.teammate_index != 0: return if self.end: return env = environment.Environment(me, world, game, move) 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), ) # return geometry.Point(game.rink_right - 300, game.goal_net_top - game.puck_binding_range) if world.tick == 0: actions = [ training_actions.WaitForTick(100), training_actions.TakePuck(), training_actions.Stop(), training_actions.MoveToPoint( count_strike_point(env) ), training_actions.Stop(), training_actions.TurnToGoal(), training_actions.Strike(20), ] self.action_list = training_actions.ActionList(*actions) # if world.tick == 0: # self.action_list = training_actions.ActionList( # training_actions.WaitForTick(100), # training_actions.TakePuck(), # training_actions.Stop(), # training_actions.MoveToPoint( # geometry.Point(shortcuts.field_center(env).y, shortcuts.opponent_player(env).net_top) # ), # training_actions.Stop(), # training_actions.MoveToPoint( # geometry.Point(world.width - 350, shortcuts.opponent_player(env).net_top) # ), # # training_actions.MoveToPoint( # # geometry.Point(380, shortcuts.field_center(env).y) # # ), # training_actions.Stop(), # ) if self.action_list.do(env): return # x1 = world.puck.x # y1 = world.puck.y # vx2 = world.puck.speed_x # vy2 = world.puck.speed_y # x3 = game.rink_right # y3 = game.goal_net_top + game.goal_net_height # x4 = game.rink_right + game.goal_net_width # y4 = game.goal_net_top + game.goal_net_height # print 'vx2, vy2', vx2, vy2 # if geometry.ray_interval_intersection(x1, y1, vx2, vy2, x3, y3, x4, y4): if prediction.goalie_can_save_straight(env): print 'F**K YOU' else: print 'GOAL' self.end = True