Beispiel #1
0
    def call_agent(self, agent: BaseAgent, agent_class):
        self.state_queue.put(self.game_tick_packet)
        _ = agent.get_output(self.game_tick_packet)
        controller_input = self.action_queue.get()
        if controller_input is None:
            get_logger("BotManager" + str(self.index))\
                .error("Agent %s did not return any output.", str(agent_class.__name__))
            return

        player_input = self.bot_input

        if isinstance(controller_input, list):
            # Write all player inputs
            get_logger("BotManager" + str(self.index)).error(
                "Sending legacy packet type, please convert to v4")
            controller_input = agent.convert_output_to_v4(controller_input)

        player_input.throttle = controller_input.throttle
        player_input.steer = controller_input.steer
        player_input.pitch = controller_input.pitch
        player_input.yaw = controller_input.yaw
        player_input.roll = controller_input.roll
        player_input.jump = controller_input.jump
        player_input.boost = controller_input.boost
        player_input.handbrake = controller_input.handbrake
        self.game_interface.update_player_input(player_input, self.index)
Beispiel #2
0
    def call_agent(self, agent: BaseAgent, agent_class):
        # Call begin rendering on the agent's behalf. If they call begin_rendering again internally, no harm done.
        agent.renderer.begin_rendering()

        controller_input = agent.get_output(self.game_tick_packet)
        if controller_input is None:
            get_logger("BotManager" + str(self.index))\
                .error("Agent %s did not return any output.", str(agent_class.__name__))
            return

        player_input = self.bot_input

        if isinstance(controller_input, list):
            # Write all player inputs
            get_logger("BotManager" + str(self.index)).error("Sending legacy packet type, please convert to v4")
            controller_input = agent.convert_output_to_v4(controller_input)

        player_input.throttle = controller_input.throttle
        player_input.steer = controller_input.steer
        player_input.pitch = controller_input.pitch
        player_input.yaw = controller_input.yaw
        player_input.roll = controller_input.roll
        player_input.jump = controller_input.jump
        player_input.boost = controller_input.boost
        player_input.handbrake = controller_input.handbrake
        if hasattr(controller_input, 'use_item'):
            # This is needed for rare cases where bots don't conform to the spec,
            # e.g. Stick returns itself rather than a SimpleControllerState.
            player_input.use_item = controller_input.use_item
        self.game_interface.update_player_input(player_input, self.index)

        # Send the rendering at the end, to minimize any impact on latency. The agent may have already called
        # end_rendering internally, if that's the case then this will just no-op.
        agent.renderer.end_rendering()
    def call_agent(self, agent: BaseAgent, agent_class):
        controller_input = agent.get_output(self.game_tick_packet)
        if controller_input is None:
            get_logger("BotManager" + str(self.index))\
                .error("Agent %s did not return any output.", str(agent_class.__name__))
            return

        player_input = self.bot_input

        if isinstance(controller_input, list):
            # Write all player inputs
            get_logger("BotManager" + str(self.index)).error(
                "Sending legacy packet type, please convert to v4")
            controller_input = agent.convert_output_to_v4(controller_input)

        player_input.throttle = controller_input.throttle
        player_input.steer = controller_input.steer
        player_input.pitch = controller_input.pitch
        player_input.yaw = controller_input.yaw
        player_input.roll = controller_input.roll
        player_input.jump = controller_input.jump
        player_input.boost = controller_input.boost
        player_input.handbrake = controller_input.handbrake
        if hasattr(controller_input, 'use_item'):
            # This is needed for rare cases where bots don't conform to the spec,
            # e.g. Stick returns itself rather than a SimpleControllerState.
            player_input.use_item = controller_input.use_item
        self.game_interface.update_player_input(player_input, self.index)