A neural network-based self-driving car simulation built with pure JavaScript, demonstrating artificial intelligence and machine learning concepts in a real-time driving environment.
This simulation implements a self-driving car that navigates through traffic using a custom neural network. The car uses sensor inputs to make driving decisions, providing a practical demonstration of AI and machine learning principles.
- Neural Network AI: Custom-built neural network for autonomous driving decisions
- Sensor System: Ray-casting sensors for obstacle and road boundary detection
- Real-Time Visualization: Live visualization of neural network decision processes
- Traffic Simulation: Multiple AI-controlled vehicles for realistic driving scenarios
- Training System: Save and load functionality for the best-performing neural networks
self-driving-car/
├── index.html # Main HTML file
├── style.css # Application styling
├── main.js # Core application logic and animation
├── car.js # Car physics and AI controls
├── road.js # Road generation and management
├── sensor.js # Sensor system implementation
├── network.js # Neural network architecture
├── visualizer.js # Neural network visualization
├── controls.js # Control system for driving
├── utils.js # Utility functions
├── car.png # Car sprite image
└── README.md # Project documentation
The neural network uses a feedforward architecture with:
- Input Layer: 5 sensor rays (configurable)
- Hidden Layer: 6 neurons
- Output Layer: 4 neurons (forward, left, right, reverse controls)
- Open
index.html
in a web browser to start the simulation - The AI car will automatically begin navigating through traffic
- Interface controls:
- Save Button: Save the current best neural network to localStorage
- Discard Button: Remove saved network and reset simulation
- Acceleration and friction modeling
- Collision detection with road borders and vehicles
- Damage assessment system
- Turning mechanics based on speed
- Ray-casting implementation for environmental scanning
- Multiple sensor configuration for comprehensive detection
- Distance measurement to obstacles
- Custom implementation without external dependencies
- Feedforward propagation
- Mutation capabilities for training optimization
- Local storage integration for model persistence
To run the simulation:
- Download or clone the project files
- Open
index.html
in any modern web browser - The simulation will start automatically
The AI learning process follows these steps:
- Generate multiple cars with varied neural network configurations
- Evaluate performance based on distance traveled
- Select and save the best-performing neural network
- Use mutation to explore new behavioral patterns
- Repeat the process for continuous improvement
The project supports various modifications:
- Sensor configuration in
sensor.js
- Neural network architecture in
network.js
- Traffic patterns in
main.js
- Physics parameters in
car.js
This project demonstrates:
- Neural network fundamentals and implementation
- Genetic algorithms and evolutionary strategies
- Computer vision concepts through ray-casting
- Real-time physics simulation
- Canvas-based graphics rendering