This is a simple asteroids clone using pygame and NEAT modules to train an AI agent to play the game.
This game was originally developed in September 2021 to learn Python and experiment with AI models in preperation for an upcoming school project. The training process can be started and observed, however the model cannot be saved as of now.
- Python 3.6 or later
- pygame
- NEAT-Python
To install the required dependencies, run the following command:
pip3 install pygame neat-python
You only need to run the python script with the following code and the agent will start to play the game.
python3 training.py
At the moment, the agent does random things, as the fitness value is only tied to the score and movement of the ship. Feel free to adapt this in the training.py
file using the g.fitness
variable.
NOTE: To stop the training at any point, use Ctrl+C in the command line to exit the program entirely.
Currently, the trained model is not saved. This still needs to be implemented.
Start the game with
python3 game.py
The bar on top displays your health. You lose health every time an asteroid hits you.
Move the ship around with the arrow buttons: :arrow_up: Accelerate :arrow_left: Rotate counterclockwise :arrow_right: Rotate clockwise
Shoot the asteroids with the space bar. Be careful, as bigger ones will split into two.
Thanks to Tech With Tim for his tutorial on a Flappy Bird game using NEAT. It was followed and used as an inspiration for this project. Icon image by Clker-Free-Vector-Images from Pixabay