This project is an AI Racing Simulator built using Python, Pygame, and NEAT (NeuroEvolution of Augmenting Topologies). The simulator trains cars to navigate through a racing map using neural networks and evolutionary algorithms.
- Python 3.x
- neat-python
- pygame
-
Clone the repository:
git clone https://github.com/maydaythecoder/ai-racing-simulator.git cd ai-racing-simulator
-
Create and activate a virtual environment:
python -m venv venv .\venv\Scripts\activate # On Windows source venv/bin/activate # On MacOS/Linux
-
Install the required dependencies:
pip install -r requirements.txt
Ensure you have the following dependencies in your
requirements.txt
:neat-python pygame
-
Place your car and map images in the project directory:
car.png
: Image file for the car sprite.map.png
: Image file for the racing map.
Run the simulation using the following command:
python main.py
The configuration for the NEAT algorithm is defined in the config.txt file. You can adjust parameters such as population size, number of generations, and mutation rates according to your needs.
ai-racing-simulator/
│
├── car.png
├── map.png
├── map2.png
├── map3.png
├── map4.png
├── map5.png
├── main.py
├── config.txt
├── requirements.txt
└── README.md
The main.py script contains the following key components:
Defines the properties and behaviors of the car, including movement, collision detection, and sensor (radar) calculations.
Initializes the Pygame environment, loads the map, creates neural networks for each genome, and runs the simulation loop.
Loads the NEAT configuration, creates a population, adds reporters, and runs the simulation for a specified number of generations. config.txt The config.txt file contains the configuration for the NEAT algorithm. You can modify this file to change the evolutionary parameters, such as population size, fitness threshold, and mutation rates.
Contributions are welcome! Please fork the repository and submit a pull request for any bug fixes or enhancements.
Open Source
Feel free to adjust the content and links as necessary. This README.md
provides an overview of the project, instructions for installation and usage, and details about the project's structure and configuration.