/neat-sonic-game-ai

⚡A Neuro Evolution Of Augmented Topologies (NEAT) Model trained to play the first level of Sonic The Hedgehog 2

Primary LanguagePython

neat-sonic-game-ai

Sonic NEAT Main Image

project-description (12)

This is a Python Project in which we train and test neural networks to play Sonic The Hedgehog 2 using the Neuro Evolution of Augmented Topologies (NEAT) Algorithm. There are three python scripts in this repository two of which are used for Training and one is used for Testing. The SonicAI.py script is used to train a model normally where as the the SonicParrallelization.py script uses the ParallelEvaluator feature provided by the NEAT library to train a model using Multiple Threads. In both the cases, the trained model is stored as a pickle file in the root directory which is then used to test the model by running the SonicAITest.py script.

technologies-used (12)

Python OpenAI Gym Retro NEAT Python OpenCV NumPy Figma

how-to-use-project (7)

Install the following Python libraries in your Virtual Environment using PIP.

Note: The library names are CASE-SENSITIVE for PIP installations below. Make sure your type them correctly.

Install NEAT for Python

pip install neat-python

Install OpenAI Gym Retro for Python

pip install gym-retro

Install OpenCV for Python

pip install opencv-python

Install Numpy for Python

pip install numpy

Download a copy of this repository onto your local machine and extract it into a suitable folder.

  • Create a Virtual Environment in that folder.
  • Install all the required Python libraries mentioned above.
  • Buy/Download Sonic The Hedgehog 2 game rom (.md extension) and place it in the Rom folder in the Root Directory.
  • Open a Command Prompt/Terminal in the Root Directory of the Project.
  • An Example Model is already provided in the Root Directory called SonicParrallelWinner1.pkl. To simply test the model, run the SonicAITest.py file as shown below.
python SonicAITest.py
  • If you want to train your own model, then delete/move the existing model from the root directory, and run either the SonicAI.py file or SonicParrallelization.py file.
  • if you want to train normally, run the SonicAI.py file as shown below.
python SonicAI.py
  • If you want to use your CPU to train the model in Parallel using Threads, run the SonicParrallelization.py file. as shown below. You can also change the number of Threads you want to use by changing the number on line 103 of the SonicParrallelization.py script.
python SonicParrallelization.py
  • Finally, to test your trained model, run the file mentioned in step 4.
  • Enjoying training & testing models for Sonic the Hedgehog 2 with this project!