Example #1
0
    def move_agent(self, action_name, game_interface: HFOAttackingPlayer,
                   features: BaseHighLevelState):
        """ Agent Moves/Dribbles in a specific direction """

        # Get Movement type:
        action = DRIBBLE_TO

        if "UP" in action_name:
            action = (action, features.agent.x_pos, -0.9)
        elif "DOWN" in action_name:
            action = (action, features.agent.x_pos, 0.9)
        elif "LEFT" in action_name:
            action = (action, -0.8, features.agent.y_pos)
        elif "RIGHT" in action_name:
            action = (action, 0.8, features.agent.y_pos)
        else:
            raise ValueError("ACTION NAME is WRONG")

        attempts = 0
        while game_interface.in_game() and attempts < self.action_num_episodes:
            status, observation = game_interface.step(action,
                                                      features.has_ball())
            features.update_features(observation)
            attempts += 1
        return game_interface.get_game_status(), \
            game_interface.get_observation_array()
Example #2
0
 def kick_to_pos(self, pos: tuple, features: BaseHighLevelState,
                 game_interface: HFOAttackingPlayer):
     """ The agent kicks to position expected """
     hfo_action = (KICK_TO, pos[0], pos[1], 2)
     status, observation = game_interface.step(hfo_action,
                                               features.has_ball())
     # Update features:
     features.update_features(observation)
Example #3
0
 def move_to_pos(self, pos: tuple, features: BaseHighLevelState,
                 game_interface: HFOAttackingPlayer):
     """ The agent keeps moving until reach the position expected """
     curr_pos = features.get_pos_tuple(round_ndigits=1)
     while pos != curr_pos:
         hfo_action = (MOVE_TO, pos[0], pos[1])
         status, observation = game_interface.step(hfo_action,
                                                   features.has_ball())
         # Update features:
         features.update_features(observation)
         curr_pos = features.get_pos_tuple(round_ndigits=1)
Example #4
0
 def shoot_ball(self, game_interface: HFOAttackingPlayer,
                features: BaseHighLevelState):
     """ Tries to shoot, if it fail, kicks to goal randomly """
     # Get best shoot angle:
     angles = []
     goalie_coord = np.array([features.opponents[0].x_pos,
                              features.opponents[0].y_pos])
     player_coord = np.array(features.get_pos_tuple())
     for goal_pos in self.shoot_possible_coord:
         angles.append(get_angle(goalie=goalie_coord, player=player_coord,
                                 point=goal_pos))
     idx = int(np.argmax(np.array(angles)))
     best_shoot_coord = self.shoot_possible_coord[idx]
     # Action parameters:
     hfo_action = (KICK_TO, best_shoot_coord[0], best_shoot_coord[1], 2.5)
     # Step game:
     _, obs = game_interface.step(hfo_action, features.has_ball())
     # Update features:
     features.update_features(obs)
     return game_interface.get_game_status(), \
         game_interface.get_observation_array()
Example #5
0
    def dribble_to_pos(self, pos: tuple, features: BaseHighLevelState,
                       game_interface: HFOAttackingPlayer):
        """ The agent keeps dribbling until reach the position expected """
        def check_valid_pos(pos_tuple: tuple):
            for pos_aux in pos_tuple:
                try:
                    num_digits = len(str(pos_aux).split(".")[1])
                    if num_digits >= 2:
                        return False
                except IndexError:
                    pass
            return True

        if check_valid_pos(pos) is False:
            raise Exception("Initial positions invalid. Initial positions "
                            "should be a float with 1 digit or less")
        curr_pos = features.get_pos_tuple(round_ndigits=1)
        while pos != curr_pos:
            hfo_action = (DRIBBLE_TO, pos[0], pos[1])
            status, observation = game_interface.step(hfo_action,
                                                      features.has_ball())
            # Update features:
            features.update_features(observation)
            curr_pos = features.get_pos_tuple(round_ndigits=1)
Example #6
0
 def no_ball_action(self, game_interface: HFOAttackingPlayer,
                    features: BaseHighLevelState) -> int:
     action = (MOVE, )
     status, observation = game_interface.step(action, features.has_ball())
     features.update_features(observation)
     return status
Example #7
0
 def do_nothing(self, game_interface: HFOAttackingPlayer,
                features: BaseHighLevelState):
     action = (NOOP, )
     status, observation = game_interface.step(action, features.has_ball())
     return status, observation
Example #8
0
            agent_coord = (agent_f.x_pos, agent_f.y_pos)
            team_f = features_manager.teammates[0]
            team_coord = (team_f.x_pos, team_f.y_pos)
            # Goal angles:
            agent_angle = (best_shoot_angle(agent_coord,
                                            features_manager.opponents))
            team_angle = (best_shoot_angle(team_coord,
                                           features_manager.opponents))
            # Distance to opponent:
            agent_op_dist = agent_f.proximity_op
            team_op_dist = team_f.proximity_op
            # Pass angle
            pass_angle = abs(team_f.pass_angle)

            # Agent Has ball
            if features_manager.has_ball():
                # Last action Failed (DRIBBLE):
                if last_action_failed or attempts_to_shoot >= 2:
                    attempts_to_shoot = 0
                    last_action_failed = False
                    hfo_action = DRIBBLE

                # Opponents near agent && good angle pass (PASS):
                elif agent_f.proximity_op < -0.9 and \
                        team_f.proximity_op > -0.7:
                    hfo_action = (PASS, teammate_id)

                # Far from Goal:
                elif agent_f.x_pos < 0.2:
                    # Teammate near Goal, good pass angle and far from op
                    if not teammate_further_from_goal(features_manager) and \