예제 #1
0
    def __init__(self, env, precount, history):
        super(GStrategy3, self).__init__(env, precount, history)

        if self.hwp is None or self.hwp.player_id != env.me.player_id:
            self.do_get_puck = True
            puck_nearest_hockeyist = min(
                shortcuts.my_field_hockeyists(env),
                key=lambda h: assessments.ticks_to_reach_point(env, h, env.world.puck)
            )
            self.active_puck_taker = puck_nearest_hockeyist
            def_nearest_hockeyist = min(
                filter(
                    lambda h: h.id != puck_nearest_hockeyist.id,
                    shortcuts.my_field_hockeyists(env)
                ),
                key=lambda h: assessments.ticks_to_reach_point(env, h, self.precount.defence_point)
            )
            self.defenceman = def_nearest_hockeyist
            other_hockeyist = filter(
                lambda h: h.id not in (def_nearest_hockeyist.id, puck_nearest_hockeyist.id),
                shortcuts.my_field_hockeyists(env)
            )[0]
            self.second_puck_taker = other_hockeyist
        else:
            self.strike_point = self.count_strike_point(env)
            if self.pass_condition(env, self.strike_point):
                self.do_pass = True
                self.pass_maker = self.hwp
                self.pass_taker = self.count_pass_taker(env)
                other = filter(
                    lambda h: h.id not in (self.pass_maker.id, self.pass_taker.id),
                    shortcuts.my_field_hockeyists(env)
                )[0]
                def_nearest_hockeyist = min(
                    filter(
                        lambda h: h.id != self.hwp.id,
                        shortcuts.my_field_hockeyists(env)
                    ),
                    key=lambda h: assessments.ticks_to_reach_point(env, h, self.precount.defence_point)
                )
                if other.id == def_nearest_hockeyist.id:
                    self.defenceman = other
                else:
                    self.attack_supporter = other
            else:
                self.do_goal = True
                self.attacker = self.hwp
                self.defenceman = min(
                    filter(
                        lambda h: h.id != self.attacker.id,
                        shortcuts.my_field_hockeyists(env)
                    ),
                    key=lambda h: assessments.ticks_to_reach_point(env, h, self.precount.defence_point)
                )
                other = filter(
                    lambda h: h.id not in (self.attacker.id, self.defenceman.id),
                    shortcuts.my_field_hockeyists(env)
                )[0]
                self.attack_supporter = other
예제 #2
0
    def __init__(self, env, precount, history):
        super(GStrategy2, self).__init__(env, precount, history)

        my_nearest_hockeyist = min(
            shortcuts.my_field_hockeyists(env),
            key=lambda h: assessments.ticks_to_reach_point(env, h, env.world.puck)
        )
        my_other_hockeyist = filter(
            lambda h: h.id != my_nearest_hockeyist.id,
            shortcuts.my_field_hockeyists(env)
        )[0]
        if self.hwp is None or self.hwp.player_id != env.me.player_id:
            self.do_get_puck = True
            self.defenceman = my_other_hockeyist
            self.active_puck_taker = my_nearest_hockeyist
        else:
            self.strike_point = self.count_strike_point(env)
            if self.pass_condition(env, self.strike_point):
                self.do_pass = True
                self.pass_maker = self.hwp
                self.pass_taker = filter(
                    lambda h: h.id != self.hwp.id,
                    shortcuts.my_field_hockeyists(env)
                )[0]
            else:
                self.do_goal = True
                self.attacker = self.hwp
                self.defenceman = filter(
                    lambda h: h.id != self.hwp.id,
                    shortcuts.my_field_hockeyists(env)
                )[0]
예제 #3
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
예제 #4
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
예제 #5
0
    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)