From 5d49299e460d03f4dbeeeb03f1fbdba2e8859ceb Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Tue, 6 Oct 2020 13:33:45 -0700 Subject: [PATCH] Including a script that launches RLBotGUI, and a spike rush utility. --- requirements.txt | 1 + run.bat | 11 ----------- run.sh | 5 ----- run_gui.py | 7 +++++++ src/util/spikes.py | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 16 deletions(-) delete mode 100644 run.bat delete mode 100644 run.sh create mode 100644 run_gui.py create mode 100644 src/util/spikes.py diff --git a/requirements.txt b/requirements.txt index 25c0c97..008fac3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ # Include everything the framework requires # You will automatically get updates for all versions starting with "1.". rlbot==1.* +rlbot_gui rlbottraining # This will cause pip to auto-upgrade and stop scaring people with warning messages diff --git a/run.bat b/run.bat deleted file mode 100644 index b3318d9..0000000 --- a/run.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off - -@rem Change the working directory to the location of this file so that relative paths will work -cd /D "%~dp0" - -@rem Make sure the environment variables are up-to-date. This is useful if the user installed python a moment ago. -call ./RefreshEnv.cmd - -python run.py - -pause diff --git a/run.sh b/run.sh deleted file mode 100644 index 4598972..0000000 --- a/run.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -cd "$(dirname "$0")" - -python3 ./run.py \ No newline at end of file diff --git a/run_gui.py b/run_gui.py new file mode 100644 index 0000000..a3bced8 --- /dev/null +++ b/run_gui.py @@ -0,0 +1,7 @@ +from rlbot_gui import gui + +# This is a useful way to start up RLBotGUI directly from your bot project. You can use it to +# arrange a match with the settings you like, and if you have a good IDE like PyCharm, +# you can do breakpoint debugging on your bot. +if __name__ == '__main__': + gui.start() diff --git a/src/util/spikes.py b/src/util/spikes.py new file mode 100644 index 0000000..582c30a --- /dev/null +++ b/src/util/spikes.py @@ -0,0 +1,36 @@ +from rlbot.utils.structures.game_data_struct import PlayerInfo, GameTickPacket + +from util.vec import Vec3 + +# When the ball is attached to a car's spikes, the distance will vary a bit depending on whether the ball is +# on the front bumper, the roof, etc. It tends to be most far away when the ball is on one of the front corners +# and that distance is a little under 200. We want to be sure that it's never over 200, otherwise bots will +# suffer from bad bugs when they don't think the ball is spiked to them but it actually is; they'll probably +# drive in circles. The opposite problem, where they think it's spiked before it really is, is not so bad because +# they usually spike it for real a split second later. +MAX_DISTANCE_WHEN_SPIKED = 200 + +class SpikeWatcher: + def __init__(self): + self.carrying_car: PlayerInfo = None + self.spike_moment = 0 + self.carry_duration = 0 + + def read_packet(self, packet: GameTickPacket): + ball_location = Vec3(packet.game_ball.physics.location) + closest_candidate: PlayerInfo = None + closest_distance = 999999 + for i in range(packet.num_cars): + car = packet.game_cars[i] + car_location = Vec3(car.physics.location) + distance = car_location.dist(ball_location) + if distance < MAX_DISTANCE_WHEN_SPIKED: + if distance < closest_distance: + closest_candidate = car + closest_distance = distance + if closest_candidate != self.carrying_car and closest_candidate is not None: + self.spike_moment = packet.game_info.seconds_elapsed + + self.carrying_car = closest_candidate + if self.carrying_car is not None: + self.carry_duration = packet.game_info.seconds_elapsed - self.spike_moment