🚗 AI Cars: 100 cars with neural networks learning to drive 🧠 Neural Network: 5-input, 6-hidden, 4-output network architecture 📡 Sensors: Ray-casting sensors for obstacle detection 🛣️ Environment: Multi-lane road with traffic cars 🔄 Genetic Algorithm: Evolutionary training with mutation 📊 Real-time Stats: Generation, best score, cars alive, time 💾 Persistence: Save and load best performing networks
- Inputs: 5 sensor readings (distance to obstacles)
- Hidden Layer: 6 neurons with bias
- Outputs: 4 controls (forward, left, right, reverse)
- 100 cars start with random neural networks
- Cars navigate through traffic using sensor input
- Fitness is measured by distance traveled
- Best performing car's brain is saved
- New generation created with mutations of the best brain
- Process repeats for continuous improvement
- 5 ray-casting sensors spread in a fan pattern
- Detect road boundaries and traffic cars
- Provide distance information to neural network
- Start Simulation: Begin the training process
- Pause: Pause the current simulation
- Reset: Reset to generation 0 with random networks
- Save Best: Save the best performing network to local storage
- Load Best: Load previously saved network
index.html- Main HTML file with UImain.js- Main simulation logic and genetic algorithmcar.js- Car class with physics and controlsroad.js- Road environment and lane managementsensor.js- Ray-casting sensor implementationnetwork.js- Neural network and training logicutils.js- Utility functions for math and collision detection
-
Start a local HTTP server in the project directory:
python3 -m http.server 8000
-
Open your browser and navigate to:
http://localhost:8000 -
Click "Start Simulation" to begin training
- Let the simulation run for multiple generations
- Use "Save Best" to preserve good performing networks
- Load saved networks to continue training from a good starting point
- Each generation typically lasts 30 seconds or until all cars crash
- Physics: Realistic car movement with acceleration, friction, and steering
- Collision Detection: Polygon-based collision system
- Mutation Rate: 10% mutation rate for genetic diversity
- Population Size: 100 cars per generation
- Sensor Range: 150 pixel detection range
- Sensor Count: 5 rays for environmental awareness
The simulation demonstrates how neural networks can learn complex behaviors through evolutionary algorithms, showing emergent driving behaviors as the AI learns to navigate traffic.