Ejemplo n.º 1
0
    def render(self, draw: DrawingTool):
        self.travel.render(draw)

        if self.pad and not self.pad.is_active:
            draw.color(draw.yellow)
            draw.string(self.pad.position + vec3(0, 0, 100),
                        int(self.pad.timer * 100) / 100)
Ejemplo n.º 2
0
    def render(self, draw: DrawingTool):
        self.drive.render(draw)

        if self.target_direction is not None:
            draw.color(draw.lime)
            draw.triangle(self.target - self.target_direction * 250,
                          self.target_direction)
Ejemplo n.º 3
0
    def render(self, draw: DrawingTool):
        self.travel.render(draw)

        # render target pad
        if self.pad:
            draw.color(draw.blue)
            draw.circle(self.pad.position, 50)
Ejemplo n.º 4
0
    def render(self, draw: DrawingTool):
        self.travel.render(draw)

        # draw timer if boost isn't available yet
        if self.pad and not self.pad.state == BoostPadState.Available:
            draw.color(draw.yellow)
            draw.string(self.pad.position + vec3(0, 0, 100),
                        f"spawns in: {self.pad.timer:.1f}s")
Ejemplo n.º 5
0
    def initialize_hive(self, packet: GameTickPacket) -> None:
        index = next(iter(self.drone_indices))
        self.team = packet.game_cars[index].team

        self.info = GameInfo(self.team)
        self.info.set_mode("soccar")
        self.strategy = HivemindStrategy(self.info, self.logger)
        self.draw = DrawingTool(self.renderer, self.team)
        self.drones = [Drone(self.info.cars[i], i) for i in self.drone_indices]

        self.logger.handlers[0].setLevel(
            logging.NOTSET)  # override handler level
        self.logger.setLevel(logging.INFO if RELEASE else logging.DEBUG)
        self.logger.info("Beehive initialized")
Ejemplo n.º 6
0
 def render(self, draw: DrawingTool):
     if self.aerial_strike.finished:
         draw.color(draw.pink)
         draw.crosshair(self.aerial.target)
         draw.color(draw.lime)
         draw.polyline(self._flight_path)
     else:
         self.aerial_strike.render(draw)
Ejemplo n.º 7
0
    def initialize_agent(self):
        self.info: GameInfo = GameInfo(self.index, self.team)
        self.controls: SimpleControllerState = SimpleControllerState()
        self.maneuver: Maneuver = None

        self.info.set_mode("soccar")

        self.time = 0
        self.prev_time = 0
        self.last_touch_time = 0
        self.reset_time = 0
        self.ticks = 0

        self.draw: DrawingTool = DrawingTool(self.renderer)

        self.strategy = SoccarStrategy(self.info, self.draw)

        # variables related to quick chats
        self.chat = QuickChatTool(self)
        self.last_ball_vel = 0
        self.said_gg = False
        self.last_time_said_all_yours = 0
        self.num_of_our_goals_reacted_to = 0
        self.num_of_their_goals_reacted_to = 0

        self.matchcomms_message = ""
Ejemplo n.º 8
0
    def render(self, draw: DrawingTool):
        draw.color(draw.cyan)
        draw.square(self.target_pos, 50)

        target_direction = direction(self.car.position, self.target_pos)
        draw.triangle(self.car.position + target_direction * 200,
                      target_direction,
                      up=self.car.up())
Ejemplo n.º 9
0
    def render(self, draw: DrawingTool):
        if self.driving:
            self.action.render(draw)

        draw.color(draw.orange)
        draw.crosshair(self.target)
Ejemplo n.º 10
0
 def render(self, draw: DrawingTool):
     draw.color(draw.pink)
     draw.triangle(self.car.position + self._shift_direction * 50, self._shift_direction)
Ejemplo n.º 11
0
    def render(self, draw: DrawingTool):
        if self.landing:
            draw.color(draw.cyan)
            draw.polyline(self.trajectory)

            if self.landing_pos:
                draw.crosshair(self.landing_pos)

        draw.color(draw.green)
        draw.vector(self.car.position, forward(self.aerial_turn.target) * 200)

        draw.color(draw.red)
        draw.vector(self.car.position, self.car.forward() * 200)
Ejemplo n.º 12
0
    def render(self, draw: DrawingTool):
        self.arrive.render(draw)
        draw.color(draw.lime)
        draw.circle(self.intercept.ground_pos, Ball.radius)
        draw.point(self.intercept.ball.position)

        if self.target:
            strike_direction = ground_direction(self.intercept.ground_pos,
                                                self.target)
            draw.color(draw.cyan)
            draw.triangle(self.intercept.ground_pos + strike_direction * 150,
                          strike_direction,
                          length=100)

        if not self._has_drawn_prediction:
            self._has_drawn_prediction = True
            draw.ball_prediction(self.info.ball_predictions,
                                 self.intercept.time)
Ejemplo n.º 13
0
 def render(self, draw: DrawingTool):
     super().render(draw)
     draw.color(draw.lime if self.aerialing else (
         draw.orange if self.too_early else draw.red))
     draw.polyline(self._flight_path)
Ejemplo n.º 14
0
 def render(self, draw: DrawingTool):
     if self.aerial_strike.finished:
         draw.color(draw.pink)
         draw.crosshair(self.aerial.target)
     else:
         self.aerial_strike.render(draw)
Ejemplo n.º 15
0
class Beehive(PythonHivemind):
    def __init__(self, *args):
        super().__init__(*args)
        self.info: GameInfo = None
        self.team: int = None
        self.draw: DrawingTool = None
        self.drones: List[Drone] = []
        self.strategy: HivemindStrategy = None

        self.last_latest_touch_time = 0.0

    def initialize_hive(self, packet: GameTickPacket) -> None:
        index = next(iter(self.drone_indices))
        self.team = packet.game_cars[index].team

        self.info = GameInfo(self.team)
        self.info.set_mode("soccar")
        self.strategy = HivemindStrategy(self.info, self.logger)
        self.draw = DrawingTool(self.renderer, self.team)
        self.drones = [Drone(self.info.cars[i], i) for i in self.drone_indices]

        self.logger.handlers[0].setLevel(
            logging.NOTSET)  # override handler level
        self.logger.setLevel(logging.INFO if RELEASE else logging.DEBUG)
        self.logger.info("Beehive initialized")

    def get_outputs(self, packet: GameTickPacket) -> Dict[int, PlayerInput]:
        self.info.read_packet(packet, self.get_field_info())

        # if a kickoff is happening and none of the drones have a Kickoff maneuver active, reset all drone maneuvers
        if (packet.game_info.is_kickoff_pause
                and self.info.ball.position[0] == 0
                and self.info.ball.position[1] == 0 and not any(
                    isinstance(drone.maneuver, Kickoff)
                    for drone in self.drones)):
            if len(self.drones) == 1:
                self.drones[0].maneuver = None
            else:
                self.strategy.set_kickoff_maneuvers(self.drones)

        # reset drone maneuvers when an opponent hits the ball
        touch = packet.game_ball.latest_touch
        if touch.time_seconds > self.last_latest_touch_time and touch.team != self.team:
            self.last_latest_touch_time = touch.time_seconds
            for drone in self.drones:
                if drone.maneuver and drone.maneuver.interruptible(
                ):  # don't reset a drone while dodging/recovering
                    drone.maneuver = None

        # reset drone maneuver when it gets demoed
        for drone in self.drones:
            if drone.maneuver and drone.car.demolished:
                drone.maneuver = None

        # if at least one drone doesn't have an active maneuver, execute strategy code
        if None in [drone.maneuver for drone in self.drones]:
            self.logger.debug("Setting maneuvers")
            if len(self.drones) == 1:
                self.drones[0].maneuver = teamplay_strategy.choose_maneuver(
                    self.info, self.drones[0].car)
            else:
                self.strategy.set_maneuvers(self.drones)

        for drone in self.drones:
            if drone.maneuver is None:
                continue

            # execute maneuvers
            drone.maneuver.step(self.info.time_delta)
            drone.controls = drone.maneuver.controls

            drone.maneuver.render(self.draw)

            # draw names of maneuvers above our drones
            self.draw.color(self.draw.yellow)
            self.draw.string(drone.car.position + vec3(0, 0, 50),
                             type(drone.maneuver).__name__)

            # expire finished maneuvers
            if drone.maneuver.finished:
                drone.maneuver = None

        if len(self.drones) > 1:
            self.strategy.avoid_demos_and_team_bumps(self.drones)

        self.strategy.render(self.draw)
        self.draw.execute()
        return {drone.index: drone.get_player_input() for drone in self.drones}
Ejemplo n.º 16
0
 def initialize_agent(self):
     self.info = GameInfo(self.team)
     self.info.set_mode("soccar")
     self.draw = DrawingTool(self.renderer, self.team)
Ejemplo n.º 17
0
class BotimusPrime(BaseAgent):
    RENDERING = True

    def __init__(self, name, team, index):
        super().__init__(name, team, index)
        self.info: GameInfo = None
        self.draw: DrawingTool = None

        self.tick_counter = 0
        self.last_latest_touch_time = 0

        self.maneuver: Optional[Maneuver] = None
        self.controls: SimpleControllerState = SimpleControllerState()

    def initialize_agent(self):
        self.info = GameInfo(self.team)
        self.info.set_mode("soccar")
        self.draw = DrawingTool(self.renderer, self.team)

    def get_output(self, packet: GameTickPacket):
        # wait a few ticks after initialization, so we work correctly in rlbottraining
        if self.tick_counter < 20:
            self.tick_counter += 1
            return Input()

        self.info.read_packet(packet, self.get_field_info())

        # cancel maneuver if a kickoff is happening and current maneuver isn't a kickoff maneuver
        if packet.game_info.is_kickoff_pause and not isinstance(
                self.maneuver, Kickoff):
            self.maneuver = None

        # reset maneuver when another car hits the ball
        touch = packet.game_ball.latest_touch
        if (touch.time_seconds > self.last_latest_touch_time
                and touch.player_name != packet.game_cars[self.index].name):
            self.last_latest_touch_time = touch.time_seconds

            # don't reset when we're dodging, wavedashing or recovering
            if self.maneuver and self.maneuver.interruptible():
                self.maneuver = None

        # choose maneuver
        if self.maneuver is None:
            if self.RENDERING:
                self.draw.clear()

            if self.info.get_teammates(self.info.cars[self.index]):
                self.maneuver = teamplay_strategy.choose_maneuver(
                    self.info, self.info.cars[self.index])
            else:
                self.maneuver = solo_strategy.choose_maneuver(
                    self.info, self.info.cars[self.index])

        # execute maneuver
        if self.maneuver is not None:
            self.maneuver.step(self.info.time_delta)
            self.controls = self.maneuver.controls

            if self.RENDERING:
                self.draw.group("maneuver")
                self.draw.color(self.draw.yellow)
                self.draw.string(
                    self.info.cars[self.index].position + vec3(0, 0, 50),
                    type(self.maneuver).__name__)
                self.maneuver.render(self.draw)

            # cancel maneuver when finished
            if self.maneuver.finished:
                self.maneuver = None

        if self.RENDERING:
            self.draw.execute()

        return self.controls