예제 #1
0
    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
예제 #2
0
def puck_is_heading_to_unit(env, unit):
    if shortcuts.hockeyist_with_puck(env) is not None:
        return False
    speed_abs = geometry.vector_abs(env.world.puck.speed_x, env.world.puck.speed_y)
    if speed_abs < 10:
        return False
    return geometry.ray_point_distance(
        env.world.puck,
        geometry.Point(
            env.world.puck.speed_x,
            env.world.puck.speed_y
        ),
        unit) < 60
예제 #3
0
    def do_defence_actions(self, env):
        env.move.speed_up = 1.0
        env.move.turn = env.me.get_angle_to_unit(env.world.puck)

        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

        if shortcuts.can_take_puck(env):
            env.move.action = ActionType.TAKE_PUCK
예제 #4
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)
예제 #5
0
    def __init__(self, env, precount, history):
        self.precount = precount
        self.history = history

        # global aims
        self.do_pass = False
        self.do_goal = False
        self.do_get_puck = False

        # roles
        self.pass_taker = None
        self.pass_maker = None

        self.attacker = None
        self.defenceman = None
        self.attack_supporter = None

        self.active_puck_taker = None
        self.second_puck_taker = None


        self.strike_point = None
        self.hwp = shortcuts.hockeyist_with_puck(env)
예제 #6
0
 def save_last_puck_owner(self, env):
     hockeyist_with_puck = shortcuts.hockeyist_with_puck(env)
     if hockeyist_with_puck is not None:
         self.last_puck_owner_player_id = hockeyist_with_puck.player_id
예제 #7
0
    def move(self, me, world, game, move):
        if me.state == HockeyistState.RESTING:
            return

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

        if world.tick == 0:
            if env.me.teammate_index == 0:
                print 'random seed', env.game.random_seed
            self.precount = Precount(env)
            self.history = History()

        self.save_start_game_tick(env)
        self.hwp = shortcuts.hockeyist_with_puck(env)
        if shortcuts.team_size(env) == 2:
            gstrategy = GStrategy2(env, self.precount, self.history)
        else:
            gstrategy = GStrategy3(env, self.precount, self.history)

        # FIXME move somewhere else
        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

        def match(role):
            return role is not None and role.id == env.me.id

        if gstrategy.do_goal:
            if match(gstrategy.attacker):
                self.attack_with_puck(env, gstrategy)
            elif match(gstrategy.defenceman):
                self.do_protect_goal_actions(env, gstrategy)
            elif match(gstrategy.attack_supporter):
                self.attack_without_puck(env, gstrategy)
            else:
                raise RuntimeError("no role defined for goal strategy")
        elif gstrategy.do_pass:
            if match(gstrategy.pass_taker):
                self.take_pass(env, gstrategy)
            elif match(gstrategy.pass_maker):
                self.do_pass(env, gstrategy)
            elif match(gstrategy.defenceman):
                self.do_protect_goal_actions(env, gstrategy)
            elif match(gstrategy.attack_supporter):
                self.attack_without_puck(env, gstrategy)
            else:
                raise RuntimeError('no role defined for pass strategy')
        elif gstrategy.do_get_puck:
            if match(gstrategy.defenceman):
                self.do_protect_goal_actions(env, gstrategy)
            elif match(gstrategy.active_puck_taker):
                self.do_get_puck_actions(env, gstrategy)
            elif match(gstrategy.second_puck_taker):
                self.do_get_puck_actions(env, gstrategy)
            else:
                raise RuntimeError('no role defined for get puck strategy')
        else:
            raise RuntimeError('no global strategy defined')