Skip to content

Clement-Cardot/ai-car-simulation-project

 
 

Repository files navigation

AI Car 2D Simulation

This project is a Proof of Concept for a 2D car simulation with AI. The goal is to create a simulation where the AI learns to drive a car on a track. The circuits and game mechanisms have been created by NeuralNine :

Introduction

The project is divided in two parts: the simulation and the AI. The simulation is a 2D game where the player can drive a car on a track. The AI is a neural network that learns to drive the car on the track.

Getting started

Prerequisites

  • Python >3.10

We highly recommand you to use a virtual environment to run the project. For this project we used the virtual env feature of PyCharm.

Installation

  • Clone the repository
  • Install the dependencies with pip install -r requirements.txt

Usage

Simulation

To run the simulation, run the Main.py file.

Parameters

You can change the parameters of the simulation in the main function of the Main.py file.

  • NB_CARS: Number of cars in the simulation
    This constant must be equal or lower than your number of CPU cores. If you have 4 cores, you can set this constant to 4.

  • ID_MAP: Id of the map to load
    This constant must be between 1 and 5. There are 5 maps in the game. Feel free to create your own maps and add them to the assets folder.

  • ALGO: The algorithm to use for the training.
    The available algorithms are A2C and PPO.

if __name__ == '__main__':

    NB_CARS = 8
    ID_MAP = 4
    ALGO = "A2C"

    # Start Race Server
    race = threading.Thread(target=thread_race, args=(NB_CARS, ID_MAP))
    race.start()

    if NB_CARS == 1:
        # Start Training with Mono Client
        train_monoproccess(ALGO, ID_MAP)
    else:
        # Start Training with AI Clients
        train_multiproccess(ALGO, ID_MAP, NB_CARS)

AI

For more information about how it works and how to use it, please refer to the documentation of stable-baselines and the video of NeuralNine

Car

The car is a 2D sprite that can move on the map. It has a speed and a direction. The car can move forward and backward. It can also turn left and right.

Car

Maps

Here are the maps available in the game:

Map 1

Map 1

Map 2

Map 2

Map 3

Map 3

Map 4

Map 4

Map 5

Map 5

We do not use this map in our tests because it is too difficult for the AI and does seems relevant for our tests.

MultiProcessing

The simulation is a server that runs on a thread. The AI is another server which create workers. each worker is a client that connects to the server. The server sends the state of the game to the client. The client sends the action to the server. The server applies the action to the game and sends the new state to the client. The client receives the new state and sends the new action to the server. And so on...

Here is a diagram of the process:

MultiProcessing

About us

This project has been created by a group of students from the ESEO Engineering School in Angers, France. We are 3 students in the 5th year of the school, in the Software Engineering and Artificial Intelligence specialization.

About

A simple self-driving AI car game, which uses NEAT.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%