Example #1
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 #2
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 #3
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()