This project implements a self-learning car simulation where a car learns to navigate through a track using a neural network that is trained through genetic algorithms. The entire project is built using Object-Oriented Programming (OOP) principles, providing a modular, clean, and extensible design.
The car simulation involves cars improving over generations, where the best-performing cars pass their knowledge (weights and biases) to the next generation. The core idea is inspired by natural selection, where each generation of cars "evolves" by selecting the fittest and introducing random mutations.
- Neural Network: The cars use simple feedforward neural networks to make decisions (steering, acceleration).
- Genetic Algorithm: The neural networks are trained using a genetic algorithm that selects the best-performing cars and applies crossover and mutation to create the next generation.
- Object-Oriented Design: Key components like Car, NeuralNetwork, and Controls are modeled as separate classes.
- Simulation Environment: A track and cars are rendered in a 2D environment (using Canvas).
- Collision Detection: Each car can sense the track boundaries using sensors and adjust its movement accordingly.
- Fitness Function: Cars are evaluated based on their distance traveled on the track without crashing.
- Real-time Visualization: Watch cars improve their performance across generations as they learn to drive through the track.
- Initialization: A population of cars is created with random neural networks.
- Evaluation: Each car navigates the track. The car's performance is evaluated using a fitness function (e.g., distance traveled).
- Selection: The best-performing cars are selected based on their fitness scores.
- Crossover: Neural networks from selected cars are combined to create new cars for the next generation.
- Mutation: Random changes are introduced to the neural network weights to ensure diversity and avoid local minima.
- Next Generation: The process repeats for several generations, gradually improving the performance of the cars.
-
Clone this repository:
git clone https://github.com/harshxll/Self-Driving-Car.git
-
Open the project directory:
cd self-driving-car-simulation -
Open
index.htmlin your preferred browser to start the simulation:open index.html
Alternatively, you can use a local server for a smoother experience:
npx live-server
