def set_start_game_conditions(features_manager: BaseHighLevelState,
                              hfo_interface: HFOAttackingPlayer,
                              wait: bool,
                              fixed_position: bool = False):
    ball_pos = [features_manager.agent.ball_x, features_manager.agent.ball_y]
    starting_corners = get_vertices_around_ball(ball_pos)
    start_pos = random.choice(starting_corners)

    aux_counter = 0
    if wait:
        while hfo_interface.in_game():
            msg = hfo_interface.hfo.hear()
            if msg == settings.PLAYER_READY_MSG:
                # print("\n[HELIOS] HEARD MESSAGE!! Start Playing\n")
                break
            else:
                if fixed_position:
                    hfo_action = (MOVE_TO, start_pos[0], start_pos[1])
                    _, observation = hfo_interface.step(hfo_action)
                else:
                    _, observation = hfo_interface.step(NOOP)
                features_manager.update_features(observation)
            aux_counter += 1
            if aux_counter == 120:
                # print("\n[HELIOS] STILL WAITING!! Start Playing\n")
                break
    return
 def set_starting_game_conditions(self,
                                  start_pos: tuple = None,
                                  starts_fixed_position: bool = True,
                                  verbose: bool = False):
     """
     Set starting game conditions. Move for initial position, for example
     """
     if starts_fixed_position:
         if not start_pos:
             ball_pos: list = list(self.features.get_ball_coord())
             starting_corners = get_vertices_around_ball(ball_pos)
             start_pos = random.choice(starting_corners)
         self.actions.move_to_pos(start_pos)
         if verbose:
             print(f"[PLAYER: GAME SET UP] Initial pos= {start_pos}")
     else:
         # Start in current position
         if verbose:
             print(f"[START GAME] Initial pos= RANDOM")
     # Informs the other players that it is ready to start:
     self.game_interface.hfo.say(settings.PLAYER_READY_MSG)
Exemple #3
0
    def set_starting_game_conditions(self,
                                     start_with_ball: bool = True,
                                     start_pos: tuple = None,
                                     starts_fixed_position: bool = True,
                                     verbose: bool = False):
        """
        Set starting game conditions. Move for initial position, for example
        """
        if start_with_ball:
            if starts_fixed_position:
                if not start_pos:
                    aux_idx = self.num_ep % len(self.starting_pos_list)
                    start_pos = self.starting_pos_list[aux_idx]
                self.actions.dribble_to_pos(start_pos, stop=True)
                if verbose:
                    print(f"[START GAME] Ball; {start_pos}")
            else:
                while not self.features.has_ball():
                    self.actions.move_to_ball()
                if verbose:
                    print(f"[START GAME] Ball; RANDOM")

        else:
            if starts_fixed_position:
                if not start_pos:
                    ball_pos: list = list(self.features.get_ball_coord())
                    starting_corners = get_vertices_around_ball(ball_pos)
                    start_pos = random.choice(starting_corners)
                self.actions.move_to_pos(start_pos)
                if verbose:
                    print(f"[START GAME] NO Ball; {start_pos}")
            else:
                # Start in current position
                if verbose:
                    print(f"[START GAME] NO Ball; RANDOM")
                pass
        # Informs the other players that it is ready to start:
        self.game_interface.hfo.say(settings.PLAYER_READY_MSG)