diff --git a/.gitignore b/.gitignore index 51410e9..7aa96bb 100644 --- a/.gitignore +++ b/.gitignore @@ -108,4 +108,5 @@ ENV/ /build # Gradle files -/.gradle \ No newline at end of file +/.gradle +.vscode diff --git a/README.md b/README.md index 3771948..76c2cd5 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,27 @@ # RLBotPythonExample -Example of a python bot using the RLBot framework - -## Quick Start -The easiest way to start a python bot is demonstrated here! -https://youtu.be/YJ69QZ-EX7k - -It shows you how to: -- Install the RLBot GUI -- Use it to create a new bot - -## Changing the bot - -- Bot behavior is controlled by `src/bot.py` -- Bot appearance is controlled by `src/appearance.cfg` - -See https://github.com/RLBot/RLBotPythonExample/wiki for documentation and tutorials. - -### Older Setup Technique - -**Please don't do this unless you've followed the quick start video and it doesn't work!** - -https://www.youtube.com/watch?v=UjsQFNN0nSA - -1. Make sure you've installed [Python 3.7 64 bit](https://www.python.org/ftp/python/3.7.4/python-3.7.4-amd64.exe). During installation: - - Select "Add Python to PATH" - - Make sure pip is included in the installation -1. Download or clone this repository -1. In the files from the previous step, find and double click on run-gui.bat -1. Click the 'Run' button +Example of a python bot using the RLBot framework, and customized for use +in a classroom setting. + +## Getting Started + +These instructions assume that you're attending some kind of session where +somebody is explaining RLBot and hosting the game on one main computer. + +1. Make sure you have python 3.6 or higher installed. +1. Download this specific branch of the repository: https://github.com/RLBot/RLBotPythonExample/zipball/puppy. Make sure you unzip if necessary. +1. Look in the rlbot.cfg file and make sure the `network_address` +matches what the person hosting has provided. +1. Look in the src/bot.cfg file and change the name "AnonymousBot" to something +you can recognize, so you'll know which car on the screen is yours. +1. Connect to the wireless network called RLBot. The person hosting can tell you the password. +1. Run the program. This should cause a car to appear in the game on the host computer! + - Windows: Double click on run.bat + - Mac / Linux: Open a terminal at this folder location and run `python3 run.py` +1. Open the src/bot.py file in your favorite code editor and start tinkering. +The behavior of the car should change immediately every time you save. + +## Advanced + +- Read about the data available at https://github.com/RLBot/RLBotPythonExample/wiki/Input-and-Output-Data +- Find useful constants at https://github.com/RLBot/RLBot/wiki/Useful-Game-Values +- Make your car beautiful with `src/appearance.cfg` and https://github.com/RLBot/RLBot/wiki/Bot-Customization diff --git a/requirements.txt b/requirements.txt index 25c0c97..eb66004 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,3 @@ # Include everything the framework requires # You will automatically get updates for all versions starting with "1.". rlbot==1.* -rlbottraining - -# This will cause pip to auto-upgrade and stop scaring people with warning messages -pip diff --git a/rlbot.cfg b/rlbot.cfg index b8553d8..b140ae2 100644 --- a/rlbot.cfg +++ b/rlbot.cfg @@ -1,17 +1,24 @@ [RLBot Configuration] # Visit https://github.com/RLBot/RLBot/wiki/Config-File-Documentation to see what you can put here. +networking_role = remote_rlbot_server +network_address = 192.168.1.100 [Team Configuration] # Visit https://github.com/RLBot/RLBot/wiki/Config-File-Documentation to see what you can put here. [Match Configuration] # Number of bots/players which will be spawned. We support up to max 10. -num_participants = 2 +num_participants = 1 game_mode = Soccer -game_map = Mannfield +game_map = UtopiaColiseum_Snowy +existing_match_behavior = Restart [Mutator Configuration] # Visit https://github.com/RLBot/RLBot/wiki/Config-File-Documentation to see what you can put here. +Respawn Time = 1 Second +Boost Amount = Recharge (Fast) +Rumble = Spike Rush +Match Length = Unlimited [Participant Configuration] # Put the name of your bot config file here. Only num_participants config files will be read! diff --git a/src/bot.cfg b/src/bot.cfg index c27f0fb..fef9d88 100644 --- a/src/bot.cfg +++ b/src/bot.cfg @@ -6,7 +6,7 @@ looks_config = ./appearance.cfg python_file = ./bot.py # Name of the bot in-game -name = PythonExampleBot +name = AnonymousBot [Details] # These values are optional but useful metadata for helper programs diff --git a/src/bot.py b/src/bot.py index 58511a2..915de8d 100644 --- a/src/bot.py +++ b/src/bot.py @@ -9,38 +9,55 @@ class MyBot(BaseAgent): - def initialize_agent(self): - # This runs once before the bot starts up - self.controller_state = SimpleControllerState() - def get_output(self, packet: GameTickPacket) -> SimpleControllerState: - ball_location = Vec3(packet.game_ball.physics.location) - my_car = packet.game_cars[self.index] car_location = Vec3(my_car.physics.location) + ball_location = Vec3(packet.game_ball.physics.location) - car_to_ball = ball_location - car_location + # Numbers taken from https://github.com/RLBot/RLBot/wiki/Useful-Game-Values + enemy_goal_y_value = 5200 if my_car.team == 0 else -5200 + enemy_goal_location = Vec3(0, enemy_goal_y_value, 0) - # Find the direction of our car using the Orientation class - car_orientation = Orientation(my_car.physics.rotation) - car_direction = car_orientation.forward + target = ball_location - steer_correction_radians = find_correction(car_direction, car_to_ball) + controller_state = SimpleControllerState() + controller_state.throttle = 1.0 # Positive throttle drives forward, negative drives backward + controller_state.steer = steer_toward_target(my_car, target) - 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. - action_display = "turn left" - else: - turn = 1.0 - action_display = "turn right" + # controller_state.boost = True # Use boost to go fast or fly + # controller_state.use_item = True # Use item to retract your spikes and release the ball + # controller_state.handbrake = True # Use the handbrake to slide and turn sharply + # controller_state.jump = True # The car will jump when this *transitions* from False to True - self.controller_state.throttle = 1.0 - self.controller_state.steer = turn + # These tilt the car when it's in mid-air + # controller_state.pitch = 0.0 + # controller_state.yaw = 0.0 + # controller_state.roll = 0.0 - draw_debug(self.renderer, my_car, packet.game_ball, action_display) + return controller_state + + def initialize_agent(self): + # This runs once before the bot starts up + pass + + +def steer_toward_target(my_car, target): + car_location = Vec3(my_car.physics.location) + car_to_target = target - car_location + car_orientation = Orientation(my_car.physics.rotation) + car_direction = car_orientation.forward + steer_correction_radians = find_correction(car_direction, car_to_target) + # A negative steer value turns the car left, which happens to be positive radians, so we invert + # the value here. Also multiplying by a constant to steer more sharply. Max range for steering is -1 to 1. + return clamp(-4 * steer_correction_radians, -1.0, 1.0) - return self.controller_state + +def clamp(value, minimum, maximum): + if value > maximum: + return maximum + if value < minimum: + return minimum + return value def find_correction(current: Vec3, ideal: Vec3) -> float: @@ -60,12 +77,3 @@ def find_correction(current: Vec3, ideal: Vec3) -> float: diff -= 2 * math.pi return diff - - -def draw_debug(renderer, car, ball, action_display): - renderer.begin_rendering() - # draw a line from the car to the ball - renderer.draw_line_3d(car.physics.location, ball.physics.location, renderer.white()) - # print the action that the bot is taking - renderer.draw_string_3d(car.physics.location, 2, 2, action_display, renderer.white()) - renderer.end_rendering()
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: