How to use the rlbot.agents.base_agent.SimpleControllerState function in rlbot

To help you get started, we’ve selected a few rlbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SaltieRL / Saltie / agents / self_evolving_car / self_evolving_car_agent.py View on Github external
def __init__(self, name, team, index):
        super().__init__(name, team, index)
        self.torch = torch
        self.controller_state = SimpleControllerState()
        self.frame = 0  # frame counter for timed reset
        self.brain = -1  # bot counter for generation reset
        self.pop = 10  # population for bot looping
        self.out = [None] * self.pop  # output of nets
        self.brain = -1
        self.gen = 0
        self.pos = 0
        self.botList = []  # list of Individual() objects
        self.fittest = Fittest()  # fittest object
        self.mutRate = 0.1  # mutation rate
        self.distance_to_ball = [10000] * 10000  # set high for easy minumum
        self.input_formatter = self.create_input_formatter()
        self.output_formatter = self.create_output_formatter()
github SaltieRL / Saltie / main_agent / python_example.py View on Github external
def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        controller_state = SimpleControllerState()

        ball_location = Vector2(packet.game_ball.physics.location.x, packet.game_ball.physics.location.y)

        my_car = packet.game_cars[self.index]
        car_location = Vector2(my_car.physics.location.x, my_car.physics.location.y)
        car_direction = get_car_facing_vector(my_car)
        car_to_ball = ball_location - car_location

        steer_correction_radians = car_direction.correction_to(car_to_ball)

        if steer_correction_radians > 0:
            # Positive radians in the unit circle is a turn to the left.
            turn = -1.0  # Negative value for a turn to the left.
        else:
            turn = 1.0
github samuelpmish / ExampleBots / 2_Aerial_Recovery / agent.py View on Github external
def __init__(self, name, team, index):
        self.index = index
        self.info = GameInfo(index, team)
        self.controls = SimpleControllerState()

        self.timer = 0.0
        self.action = None
github SaltieRL / Saltie / examples / Levi / output_formatter.py View on Github external
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from random import random
from rlbot.agents.base_agent import SimpleControllerState
from rlbot.utils.structures.game_data_struct import GameTickPacket
import numpy as np
from numpy import ndarray


class LeviOutputFormatter:
    controller_state = SimpleControllerState()

    def __init__(self, index):
        super().__init__()
        self.index = index
        self.controller_state = SimpleControllerState()

    def format_model_output(self, arr: ndarray, packet: GameTickPacket, batch_size=1) -> ndarray:
        if batch_size != 1:
            raise NotImplementedError
        action = arr[0]

        self.controller_state.throttle = action[0]
        self.controller_state.pitch = action[1]
        self.controller_state.boost = action[2] > semi_random(3)
        self.controller_state.handbrake = action[3] > semi_random(3)
github SaltieRL / Saltie / agents / swarm / teacher_agent.py View on Github external
def __init__(self, name, team, index):
        super().__init__(name, team, index)
        self.empty_controller = SimpleControllerState()
        self.teacher = None
        self.teacher_formatter = self.create_output_formatter()
        self.manager_path = None
github samuelpmish / ExampleBots / 1_ATBA / agent.py View on Github external
def __init__(self, name, team, index):
        self.info = GameInfo(index, team)
        self.controls = SimpleControllerState()
github SaltieRL / Saltie / examples / levi / output_formatter.py View on Github external
def __init__(self, index):
        super().__init__()
        self.index = index
        self.controller_state = SimpleControllerState()
github SaltieRL / Saltie / agents / levi / levi_agent.py View on Github external
def __init__(self, name, team, index):
        super().__init__(name, team, index)
        import torch
        self.torch = torch
        from examples.levi.cool_atba import Atba
        self.atba = Atba()
        self.empty_controller = SimpleControllerState()
github samuelpmish / ExampleBots / 2_Aerial_Recovery / agent.py View on Github external
def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        self.info.read_packet(packet)
        self.controls = SimpleControllerState()

        if self.timer < 0.05:

            position = Vector3(random.uniform(-4000, 4000),
                               random.uniform(-3000, 3000),
                               random.uniform(  500, 2000))

            velocity = Vector3(random.uniform(-1500, 1500),
                               random.uniform(-1500, 1500),
                               random.uniform(-1000, -500))

            rotation = Rotator(random.uniform(-1.5, 1.5),
                               random.uniform(-1.5, 1.5),
                               random.uniform(-1.5, 1.5))

            angular_velocity = Vector3(random.uniform(-3.0, 3.0),
github SaltieRL / Saltie / agents / main_agent / base_model_agent.py View on Github external
from rlbot.utils.logging_utils import get_logger
from rlbot.utils.structures.game_data_struct import GameTickPacket
from rlbot.utils.structures.quick_chats import QuickChats

from examples.legacy.legacy_game_input_formatter import LegacyGameInputFormatter
from examples.lstm.lstm_input_formatter import LSTMInputFormatter
from examples.legacy.legacy_output_formatter import LegacyOutputFormatter
from examples.lstm.lstm_output_formatter import LSTMOutputFormatter

import os
import sys


class BaseModelAgent(BaseAgent):
    model_holder = None
    controller_state = SimpleControllerState()

    def __init__(self, name, team, index):
        super().__init__(name, team, index)
        self.logger = get_logger(name)
        path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
        sys.path.append(path)

    def initialize_agent(self):
        # This runs once before the bot starts up
        from examples.example_model_holder import ExampleModelHolder

        self.model_holder = ExampleModelHolder(self.create_model(),
                                               self.create_input_formatter(),
                                               self.create_output_formatter())

        self.model_holder.initialize_model(load=True)