Skip to content
Eric Veilleux edited this page Aug 22, 2020 · 21 revisions

Welcome to the VirxERLU Wiki

Documentation

Example bot

from util import routines, tools, utils
from util.agent import VirxERLU, Vector


class Bot(VirxERLU):
    # If your bot encounters an error, VirxERLU will do it's best to keep your bot from crashing.
    # VirxERLU uses a stack system for it's routines. A stack is a first-in, last-out system. The stack is a list of routines.
    # VirxERLU on VirxEC Showcase -> https://virxerlu.virxcase.dev/
    # Wiki -> https://github.com/VirxEC/VirxERLU/wiki
    def init(self):
        # This is a shot between the opponent's goal posts
        # NOTE When creating these, it must be a tuple of (left_target, right_target)
        self.foe_goal_shot = (self.foe_goal.left_post, self.foe_goal.right_post)

    def run(self):
        # If the stack is clear
        if self.is_clear():
            # If the kickoff is done
            if self.kickoff_done:
                # If we have more than 36 boost
                if self.me.boost > 36:
                    # This is were we'll store the shots we find
                    shots = []

                    # Find a jump shot that will put the ball between the posts
                    jump_shot = tools.find_jump_shot(self, self.foe_goal_shot)

                    # If we found a shot
                    if jump_shot is not None:
                        # Put the shot in the shots list
                        shots.append(jump_shot)

                    # Find a double jump shot that will put the ball between the posts
                    double_jump_shot = tools.find_double_jump(self, self.foe_goal_shot)

                    # If we found a shot
                    if double_jump_shot is not None:
                        # Put the shot in the shots list
                        shots.append(double_jump_shot)

                    # Find a aerial shot that will put the ball between the posts
                    aerial_shot = tools.find_aerial(self, self.foe_goal_shot)

                    # If we found a shot
                    if aerial_shot is not None:
                        # Put the shot in the shots list
                        shots.append(aerial_shot)

                    # If we found any shot
                    if len(shots) > 0:
                        # If we found more than 1 shot
                        if len(shots) > 1:
                            # Sort the list by it's intercept time
                            shots.sort(key=lambda shot: shot.intercept_time)

                        # Push the quickest shot to the stack
                        self.push(shots[0])
                    # If we didn't find a shot
                    else:
                        # Retreat back to the net
                        self.push(routines.retreat())
                else:
                    # Get a list of all of the large, active boosts
                    boosts = [boost for boost in self.boosts if boost.active and boost.large]
                    # Sort the boosts by how close they are to the bot
                    boosts.sort(key=lambda boost: boost.location.dist(self.me.location))
                    # Goto the nearest boost
                    self.push(routines.goto_boost(boosts[0]))

            # If the kickoff isn't done
            else:
                # Push a generic kickoff to the stack
                self.push(routines.generic_kickoff())

    def demolished(self):
        # If the stack isn't clear
        if not self.is_clear():
            # Clear the stack
            self.clear()

    def handle_match_comm(self, msg):
        # This is for handling any incoming match communications
        # All match comms are Python objects
        if msg.get('team') is self.team:
            self.print(msg)

    def handle_quick_chat(self, index, team, quick_chat):
        # This is for handling any incoming quick chats
        # See https://github.com/RLBot/RLBot/blob/master/src/main/flatbuffers/rlbot.fbs#L376 for a list of all quick chats
        if self.team is team:
            self.print(quick_chat)
Clone this wiki locally