Home

Awesome

Xbox Game AI

Our goal is to make this into a modular framework for making AIs with Xbox games that haven't been made compatible with Gym.

Based on TensorKart1, adapted to use PYXInput for control of Xbox/PC games. Has a CV-based method for driving an autonomous car inside of Forza Horizon.

Getting Started

  1. I would recommend using an Anaconda environment for easier library management. Once you have a Conda environment, enter it and clone this repository. Then, run conda install --file requirements.txt to install the necessary libraries.
  2. Install Intel OpenVINO, this is needed for the road segmentation AI model used by default.
  3. Out of the box, running play.py will attempt to find an image of a road from Forza Horizon 3 and and autonomously drive the car.
  4. So, turn on your game, such as Forza Horizon, preferably on a secondary monitor and get your car in a stable position. Then run play.py and you should start seeing the car move after a few seconds.

Note: Make sure to use Python 3.6 if you are using requirements.txt.

Dependencies

If you already have a Python installation you want to use, here are the major dependencies:

Standard AI Mode - Collect, Train, Test

TensorKart, which this is based upon, was designed to collect screenshots along with matching gamepad data, and learn what images on the screen correspond with what controller inputs using a CNN(convolutional neural network).

Note: The following is somewhat paraphrased from the TensorKart README.

Note: For most games, not all inputs are used, or are very important to the actual functioning of the game. This can result in extremely sparse data which is harder for AI models to use. To remove some controller inputs, try replacing line 301 of utils.py with load_mini_sample or another method which operates in the same way as any of the other load_sample() methods.

Categorical AI Mode

I have also experimented with another, much more complex video game - NBA2K21. However, there are so many inputs, which are pressed so infrequently, that a standard model learns to do nothing (output values are always very close to 0). So, I manually classified each picture into 8 categories, for what the AI should do. These are defined in play.py, under "High-Level Control Methods". I then used transfer learning on EfficientNet to get a model specific to my game. Currently this part is a work in progress.

What if I don't have the game on PC?

You can also use games that you have on an Xbox with this code, using a handy app called Xbox Console Companion. It comes bundled with most Windows installations, if it is not, download it from the Windows store.

How to use it

  1. Open Xbox Console Companion, and turn on your Xbox. Both the computer and XBox should be on the same network.
  2. Go to "Connect to your Xbox One", and click on your Xbox. If it does not appear find the IP address of the Xbox and enter it.
  3. You now have a live, 2-way stream from your computer to you Xbox! I have used this sucessfully to record lots of training data, it is quite reliable, even on a wireless network.

Future Improvements:

Contributing

Don't hesitate to open a pull request or issue with functionality you want to see added, or bugs you have found!

Footnotes

  1. TensorKart uses a Gym environment. If you already have an OpenAI Gym environment for your game, you might want to take a look at that. This is more useful for games with an Xbox controller input.