Skip to content

A simple asteroids clone using pygame and NEAT modules to train an AI agent to play the game.

License

Notifications You must be signed in to change notification settings

tbrec3/neat-asteroids

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

This is a simple asteroids clone using pygame and NEAT modules to train an AI agent to play the game.

screenshot

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.

Requirements

  • Python 3.6 or later
  • pygame
  • NEAT-Python

Installation

To install the required dependencies, run the following command:

pip3 install pygame neat-python

Start the training

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.

How to play yourself

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.

Credits

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

About

A simple asteroids clone using pygame and NEAT modules to train an AI agent to play the game.

Topics

Resources

License

Stars

Watchers

Forks

Languages