This project implements a sophisticated Q-Learning system combined with Ensemble Learning, where a virtual car learns to navigate custom tracks through trial and error.
The AI uses multiple specialized "experts" that cooperate and compete to find the best driving strategy.
Create custom tracks using intuitive drawing tools.
- Conservative: Safe and cautious driving style
- Aggressive: Fast and bold driving behavior
- Explorer: Focused on exploring new areas
- Follower: Follows successful trajectories
- Turbo Mode: Speed up learning by 100x
- Real-Time Statistics: Monitor learning progress live
- Problem Detection: Identifies and corrects problematic zones automatically
- Python 3.8+
- Pygame 2.6.1 – Graphics rendering and interface
- NumPy 2.3.4 – Mathematical computations and arrays
- Collections – Advanced data structures
- Hashlib – Hash generation for unique state tracking
pip install pygame==2.6.1 numpy==2.3.4
python main.py
- Track: Draw the path in black
- Start Point: Mark in blue
- Finish Point: Mark in red
- Eraser: Fix mistakes in the drawing
- Press ENTER after drawing the track
- Use ARROW KEYS to drive manually
- Press ESC to return to the editor
- Click "Train" to start automatic learning
- The AI learns through trial and error
- Real-time statistics are displayed during training
- Click "TURBO 100x" to drastically accelerate training
- Ideal for quickly training on complex tracks
experts = {
'conservative': defaultdict(lambda: np.zeros(5)),
'aggressive': defaultdict(lambda: np.zeros(5)),
'explorer': defaultdict(lambda: np.zeros(5)),
'follower': defaultdict(lambda: np.zeros(5))
}
- Q-Learning: Traditional reinforcement learning
- Ensemble Learning: Combination of multiple strategies
- Problem Focus: Detects and corrects difficult zones
- Adaptive Learning: Automatically selects the best experts
- 7 sensors positioned at angles from -90° to +90°
- Edge detection with 4 distance levels
- Contextual state includes position, speed, and direction