Skip to content
VirxEC edited this page Apr 24, 2021 · 15 revisions

util/agent.py

TOURNAMENT_MODE

Default: False Use: If you're putting your bot in the botpack, or submitting to a tournament, set this value to True

Note: You MUST set this value by hand before you launch you bot.

EXTRA_DEBUGGING

Default: True Use: Make False to enable hot reloading, at the cost of the debugging GUI

Note: You MUST set this value by hand before you launch you bot.

VirxERLU(StandaloneBot)

true_name

This is your bot's "true name" - Basically, if you're bot's name is "ABot" but there's more than one of your bot in the game, this value will always be just "ABot"

Note: This value isn't meant to be modified by your bot.

gravity

The current gravitational acceleration represented by a Vector, based on the current mutator settings.

Note: This value isn't meant to be modified by your bot.

boost_accel

The current boost acceleration represented by a number, based on the current mutator settings.

Note: This value isn't meant to be modified by your bot.

boost_amount

One of 5 strings: "default", "unlimited", "slow recharge", "fast recharge", or "no boost" - based on the current mutator settings.

Note: This value isn't meant to be modified by your bot.

game_mode

One of 6 strings: "Soccer", "Hoops", "Dropshot", "Hockey", "Rumble", or "Heatseeker" - based on the current mutator settings.

Note: This value isn't meant to be modified by your bot.

ball_radius

The radius of the ball - based on the current mutator settings.

Note: This value isn't meant to be modified by your bot.

friends

A list of the bot's teammates. Each bot is represented by a car_object.

Note: This value isn't meant to be modified by your bot.

foes

A list of the bot's foes. Each bot is represented by a car_object.

Note: This value isn't meant to be modified by your bot.

me

This is the bot represented by a car_object.

Note: This value isn't meant to be modified by your bot.

ball_to_goal

The distance from the ball to the bot's goal.

Note: This value isn't meant to be modified by your bot.

ball

This is the ball, as represented by a ball_object.

Note: This value isn't meant to be modified by your bot.

game

This is miscellaneous game information, as represented by a game_object.

Note: This value isn't meant to be modified by your bot.

boosts

A list of the field's boost pads. Each boost pad is represented by a boost_object.

Note: This value isn't meant to be modified by your bot.

friend_goal

Your bot's goal, as represented by a goal_object.

Note: This value isn't meant to be modified by your bot.

foe_goal

The enemy team's goal, as represented by a goal_object.

Note: This value isn't meant to be modified by your bot.

stack

This is a list of routines that the bot is to run. The last routine in this list is ran (it's a "first in, last out" system).

Note: Use push(self, routine) and pop(self) to modify this value.

time

The amount of time the game has been running for.

Note: This value isn't meant to be modified by your bot. It's a shortcut for game.time.

controller

This is the controls that are to be returned from the bot. Everything is defaulted to either 0 or False every tick.

kickoff_done

Whether or not the kickoff routine is done. If this is False and the stack is clear (use is_clear(self)), then you should push a kickoff routine to the stack using push(self, routine).

Example:

if self.kickoff_done:
    pass  # Run the main code here
elif not self.is_clear():
    self.push(routines.generic_kickoff())  # Push a kickoff routine to the stack
# Don't change anything

Note: This value isn't meant to be modified by your bot.

shooting

Whether or not the bot is shooting the ball.

Note: This value isn't meant to be modified by your bot.

odd_tick

This can be 0, 1, 2, or 3. Use this for things that don't have to be called every tick.

Example:

# This is ran at 30 tps
if self.odd_tick == 0:
    pass

# This is ran at 60 tps
if self.odd_tick % 2 == 0:
    pass

Note: This value isn't meant to be modified by your bot.

delta_time

The time that's passed between the last tick and the current tick.

Note: This value isn't meant to be modified by your bot.

future_ball_location_slice

Earliest that the enemy can be at the ball. Default 180.

Note: This value won't change unless your bot changes it.

min_intercept_slice

Earliest that the bot itself can be at the ball. Default 180.

Note: This value won't change unless your bot changes it.

ball_prediction_struct

This is the ball prediction struct. There's 60 slices per second, and the struct goes 6 seconds into the future.

Note: This value isn't meant to be modified by your bot.

push(self, routine)

Pushes (adds) a routine to the end of the stack, where it will be executed.

  • routine - A routine from util/routines.py

pop(self)

Pops (removes) the last routine in stack.

line(self, start, end, color=None)

Draws a line from start to end, with a color as defined by color.

  • start - A Vector that represents the starting point of the line.
  • end - A Vector that represents the ending point of the line.
  • color - A list, tuple, or pre-made color (see this wiki page) - if you don't define a color, it will default to grey.

polyline(self, vectors, color=None)

Draws a line with multiple points as defined by vectors, with a color as defined by color

  • vectors - A list or tuple of Vectors that represents each of the points in the line.
  • color - A list, tuple, or pre-made color (see this wiki page) - if you don't define a color, it will default to grey.

sphere(self, location, radius)

Draws 7 lines that vaguely resemble a sphere at location with a length of radius.

  • location - A Vector that represents the location of the middle of the sphere.
  • radius - A number.

print(self, item)

Prints item to the console, along with the name of the bot and which team the bot is on.

  • item - Any value that can be converted to a string.

dbg_3d(self, item)

Shows item in-game, at the bot's location.

  • item - Any value that can be converted to a string.

dbg_2d(self, item)

Shows item in-game, on the user's screen.

  • item - Any value that can be converted to a string.

clear(self)

Clears the stack.

is_clear(self)

Returns if the stack is empty or not.

get_minimum_game_time_to_ball(self)

This is a method that your bot must implement if it wants the built-in VirxERLU TMCP handler to not send out -1 with the TMCP action READY.

Example:

def get_minimum_game_time_to_ball(self):
    shot = tools.find_any_shot(self)
    return -1 if shot is None else shot.intercept_time

handle_tmcp_packet(self, packet)

Gets called any time there's a new TMCP packet.

By default, it set's the corresponding bot's tmcp_action property to the action key in the packet.

You may extend this if you wish to customize it.

Example:

def handle_tmcp_packet(self, packet):
    super().handle_tmcp_packet(packet)

    # do stuff with packet
    if packet.get('action').upper() == "BOOST":
        self.print(f"{packet['index']} is going to try and demo {packet['action']['target']}!")

create_tmcp_packet(self)

Converts the current state of the bot into a TMCP packet.

You may override this if you wish to customize it.

car_object

name

The bot's in-game name.

Note: This value isn't meant to be modified by your bot.

true_name

The bot's "true name" - Basically, if the bot's name is "ABot" but there's more than one of the bot in the game, this value will always be just "ABot"

Note: This value isn't meant to be modified by your bot.

team

The team that the bot is on - either 0 or 1.

Note: This value isn't meant to be modified by your bot.

location

The car's location, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

orientation

The car's orientation, represented by a Matrix3.

Note: This value isn't meant to be modified by your bot.

velocity

The car's velocity, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

angular_velocity

The car's angular velocity, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

demolished

Whether or not the car is demolished.

Note: This value isn't meant to be modified by your bot.

airborne

Whether or not the car is airborne.

Note: This value isn't meant to be modified by your bot.

supersonic

Whether or not the car is supersonic.

Note: This value isn't meant to be modified by your bot.

jumped

Whether or not the car has jumped.

Note: This value isn't meant to be modified by your bot.

doublejumped

Whether or not car has double jumped.

Note: This value isn't meant to be modified by your bot.

boost

The amount of boost the car has, from 0 to 100.

Note: This value isn't meant to be modified by your bot.

index

The index of the car.

Note: This value isn't meant to be modified by your bot.

land_time

The time that the car landed on the ground.

Note: This value isn't meant to be modified by your bot.

hitbox

The hitbox of the car, represented by a hitbox_object.

Note: This value isn't meant to be modified by your bot.

forward

A normalized Vector pointing forwards relative to the cars orientation and location.

Note: This value isn't meant to be modified by your bot. This is also an alias of orientation.forward.

right

A normalized Vector pointing right relative to the cars orientation and location.

Note: This value isn't meant to be modified by your bot. This is also an alias of orientation.right.

up

A normalized Vector pointing up relative to the cars orientation and location.

Note: This value isn't meant to be modified by your bot. This is also an alias of orientation.up.

rotation

A tuple of the car's orientation in the format (forward, right, up).

Note: This value isn't meant to be modified by your bot. This is also an alias of orientation.rotation.

pitch

A number representing the pitch of the car. Goes from -PI to PI.

Note: This value isn't meant to be modified by your bot. This is also an alias of orientation.pitch.

yaw

A number representing the yaw of the car. Goes from -PI to PI. This is also an alias of orientation.yaw.

Note: This value isn't meant to be modified by your bot.

roll

A number representing the roll of the car. Goes from -PI to PI. This is also an alias of orientation.roll.

Note: This value isn't meant to be modified by your bot.

local(self, value)

Localizes a value according to the car's orientation. Returns a Vector. Don't use this unless you know what you're doing - you should look into local_velocity(self, velocity=None) and local_location(self, location).

  • value - A value rooted in the center of the field to be localized.

Note: The opposite of this function is global_

global_(self, value)

Globalizes a local value according to the car's orientation. Returns a Vector. Don't use this unless you know what you're doing - you should look into global_location(self, location).

  • value - A value rooted in the car's orientation to be globalized.

Note: The opposite of this function is local

local_velocity(self, velocity=None)

Localizes a velocity according to the car's orientation. Returns a Vector.

  • x is the velocity forwards (+) or backwards (-) relative to the car.

  • y is the velocity to the right (+) or left (-) relative to the car.

  • z if the velocity upwards (+) or downwards (-) relative to the car.

  • velocity - A velocity Vector. If a value isn't passed, it will default to the car's own velocity.

local_location(self, location)

Localizes a location according to the car's orientation. Returns a Vector.

  • x is how far the location is forwards (+) or backwards (-) relative to the car.

  • y is the velocity to the right (+) or left (-) relative to the car.

  • z is how far the location is upwards (+) or downwards (-) relative to the car.

  • location - A location Vector.

Note: The opposite of this function is global_location

global_location(self, location)

Globalizes a local location according to the car's orientation. Returns a Vector.

  • location - A local location Vector.

Note: The opposite of this function is local_location

local_flatten(self, value)

Locally flattens a global value according to the car's orientation.

  • value - A value rooted in the center of the field to be locally flattened.

local_flatten_location(self, location)

Locally flattens a global location according to the car's orientation.

  • location - A location rooted in the center of the field to be locally flattened.

get_raw(self, agent, force_on_ground=False)

Returns all of the data in car_object but with only lists, tuples, ints, and floats

  • agent - An instance of VirxERLU. If you're running this from an instance of VirxERLU, pass in self.
  • force_on_ground - Forces airborne to be 0 in the data. Default False.

hitbox_object

length

The length of the hitbox.

Note: This value isn't meant to be modified by your bot.

width

The width of the hitbox.

Note: This value isn't meant to be modified by your bot.

height

The height of the hitbox.

Note: This value isn't meant to be modified by your bot.

offset

The hitbox offset.

Note: This value isn't meant to be modified by your bot.

hitbox_sphere

diameter

The diameter of the hitbox.

Note: This value isn't meant to be modified by your bot.

hitbox_cylinder

height

The height of the hitbox.

Note: This value isn't meant to be modified by your bot.

diameter

The diameter of the hitbox.

Note: This value isn't meant to be modified by your bot.

last_touch

location

The location of the last touch, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

normal

Which direction the ball was hit from, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

time

The time that the ball was last touched

Note: This value isn't meant to be modified by your bot.

car

The bot that last touched the ball, represented by a car_object.

Note: This value isn't meant to be modified by your bot.

ball_shape

type

A number that's 0 for a cube/cuboid, 1 for a sphere, and 2 for a cylinder.

Cubes/cuboids are represented by a hitbox_object.

Spheres are represented by a hitbox_sphere.

Cylinder are represented by a hitbox_cylinder.

ball_object

location

The location of the ball, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

velocity

The velocity of the ball, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

last_touch

Information about the last ball touch, represented by a last_touch

shape

Information about the ball's hitbox, represented by a ball_shape

get_raw(self)

Returns all of the data in ball_object but with only lists, tuples, ints, and floats

  • agent - An instance of VirxERLU. If you're running this from an instance of VirxERLU, pass in self.

boost_object

index

The index of the boost pad.

Note: This value isn't meant to be modified by your bot.

location

The location of the boost pad, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

active

Whether or not the boost pad is active, and a bot can pick it up.

Note: This value isn't meant to be modified by your bot.

large

Whether or not the boost pad is large.

Note: This value isn't meant to be modified by your bot.

goal_object

location

The center of the goal, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

left_post

The center of the left post, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

right_post

The center of the right post, represented by a Vector.

Note: This value isn't meant to be modified by your bot.

game_object

gravity

The current gravitational acceleration represented by a Vector.

Note: This value isn't meant to be modified by your bot.

time

The seconds elapsed since the game started.

Note: This value isn't meant to be modified by your bot.

time_remaining

The second remaining in the game.

Note: This value isn't meant to be modified by your bot.

overtime

Whether or not the game is in overtime.

Note: This value isn't meant to be modified by your bot.

round_active

Whether or not the game is active.

Note: This value isn't meant to be modified by your bot.

kickoff

Whether or not the game is in its 3-second kickoff pause.

Note: This value isn't meant to be modified by your bot.

match_ended

Whether or not the match has ended.

Note: This value isn't meant to be modified by your bot.

friend_score

The bot's team score.

Note: This value isn't meant to be modified by your bot.

foe_score

The bot's enemy score.

Note: This value isn't meant to be modified by your bot.

Matrix3

The Matrix3's sole purpose is to convert roll, pitch, and yaw data from the gametickpacket into an orientation matrix.

pitch

A number representing the pitch of the car. Goes from -PI to PI.

Note: This value isn't meant to be modified by your bot.

yaw

A number representing the yaw of the car. Goes from -PI to PI.

Note: This value isn't meant to be modified by your bot.

roll

A number representing the roll of the car. Goes from -PI to PI.

Note: This value isn't meant to be modified by your bot.

rotation

A list of the [forward, right, up] determined by the input data.

Note: This value isn't meant to be modified by your bot.

forward

Equivalent to data[0].

Note: This value isn't meant to be modified by your bot.

right

Equivalent to data[1].

Note: This value isn't meant to be modified by your bot.

up

Equivalent to data[2].

Note: This value isn't meant to be modified by your bot.

from_rotator(rotator)

Creates a Matrix3 object from another object that defines the properties roll, pitch and yaw.

Example:

my_matrix = Matrix3.from_rotator(packet.game_cars[self.index].physics.rotation)

from_direction(direction, up)

Creates a Matrix3 object from some forward direction and some up direction.

Example:

my_matrix = Matrix3.from_rotator(Vector(1, 0, 0), Vector(0, 0, 1))

dot(self, vector)

Localizes a vector rooted in the center of the field, and returns a Vector.

  • vector - A Vector rooted in the center of the field.

det(self)

Returns the detriment of the matrix.

Vector

Vector supports 1D, 2D and 3D Vectors, as well as calculations between them. Arithmetic with 1D and 2D lists/tuples aren't supported - just set the remaining values to 0 manually. With this new setup, Vector is much faster because it's just a wrapper for numpy.

x

The X coordinate. Defaults to 0.

y

The Y coordinate. Defaults to 0.

z

The Z coordinate. Defaults to 0.

from_vector

Creates a Vector object from another object that defines the properties x, y and z.

Example:

my_vector = Vector.from_vector(packet.game_cars[self.index].physics.location)

magnitude(self)

Returns the distance from the vector to (0, 0, 0), aka the vector's Euclidean length.

normalize(self, return_magnitude=False)

Returns a Vector that shares the same direction but has a length of 1.

  • return_magnitude - If True, the method will return the normalized vector and the original vector's length. Used for optimization.

dot(self, value)

Returns the dot product of the 2 vectors.

cross(self, value)

Returns the cross product of the 2 vectors.

flatten(self)

Returns a Vector that has had it's z coordinate set to 0.

copy(self)

Returns a copy of the vector.

angle2D(self, value)

Returns the angle (in radians) between the 2 vectors after they've been flattened.

angle(self, value)

Returns the angle (in radians) between the 2 vectors.

rotate(self, angle)

Returns the vector, but rotated by angle radians.

  • angle - Number of radians to rotate the vector by.

clamp2D(self, start, end)

Returns the Vector's direction between a start and end Vector such that start < Vector < end in terms of clockwise rotation. This is only for the x and y coordinates, not the z.

clamp(self, start, end)

Returns the Vector's direction between a start and end Vector such that start < Vector < end in terms of clockwise rotation.

dist(self, value)

Returns the distance between the 2 vectors.

flat_dist(self, value)

Returns the distance between the 2 vectors, after they've been flattened.

cap(self, low, high)

Returns the vector, but all the values in the Vector have been capped between low and high.

  • low - A number.
  • high - A number.

midpoint(self, value)

Returns the midpoint of the 2 vectors.

scale(self, value)

Scales self to a magnitude of value.

  • value - A number.
Clone this wiki locally