Viewed settings.py:1-50 Viewed neural_network.py:1-147 Viewed fitness.py:1-88
Here are the filled-out write-up sections for Morning Pursuit / Neon Drift, formatted for Devpost, project showcases, or hackathon submissions:
💡 Inspiration
Most traditional 2D racing and pursuit games rely on hardcoded if/else rules, static waypoints, or scripted pathfinding for enemy vehicles. While predictable, these bots break down when players adopt creative driving strategies, quickly becoming repetitive and easy to outsmart.
We wanted to create an opponent that thinks, adapts, and learns to hunt. Instead of scripting how the enemy should drive, we asked: Can we train an artificial intelligence inside Pygame using natural selection, making the enemy progressively smarter and more aggressive every time you play?
🏎️ What it does
Morning Pursuit (Neon Drift) is an interactive 2D retro-synthwave highway pursuit simulator built in Python.
- The Gameplay: You pilot a high-speed vehicle navigating dense scrolling traffic. An enemy AI car starts behind you and actively tries to hunt down and intercept your car.
- The AI Brain: The pursuer isn't controlled by rigid code. It runs on a 2-layer Feedforward Neural Network ((8 \rightarrow 18 \rightarrow 2)) that evaluates 8 real-time spatial inputs (road boundaries, relative player offset, gap distance, speeds, relative velocity, and lateral drift).
- Live Evolution: When a round ends, a Genetic Algorithm evaluates the performance of a population of 40 neural brains. The top-performing pursuers reproduce and mutate. Over successive generations, random driving gives way to intentional tracking, drafting, and aggressive interception lines.
🛠️ How we built it
- Game Engine & Physics (main.py): Developed using Pygame. To simulate high-speed highway driving, we implemented a fixed vertical player camera ((Y=560)) with dynamic relative scrolling physics, tire friction decay ((\text{lateral} \times 0.72)), and Axis-Aligned Bounding Box (AABB) traffic collisions.
- Custom Neural Network Engine (neural_network.py): Written from scratch using NumPy without heavy external deep learning libraries (no PyTorch/TensorFlow). Features a lightweight architecture activated by (\text{ReLU}) for hidden features and (\text{Tanh}) for output layers to produce continuous analog steering (([-1.0, 1.0])) and smooth acceleration/braking.
- Neuroevolution Engine (population.py): Implemented a population-based evolutionary algorithm with Elitism (preserving the top 20% elite brains) and Gaussian random mutation ((14\%) rate, (0.32) strength) across candidate weight matrices.
- Fitness Metric (fitness.py): Rewards proximity to the player, continuous lane alignment directly behind the target vehicle, session duration, and awards a massive bonus (+12,000 pts) for successful interceptions.
- Persistence & Visuals (settings.py): Included JSON-based checkpoint saving for preserving top-performing brains, paired with a glowing neon synthwave UI, dynamic threat meter, and real-time telemetry HUD.
⚡ Challenges we ran into
- Unstable Early-Generation Driving: In early generations, pure random weight initialization caused AI vehicles to crash into road walls immediately. We solved this by seeding structural biases for relative offset into initial weights and implementing an adaptive pursuit blend that smoothly transitions control to pure neural outputs as fitness improves.
- Smooth Steering vs. Twitchy Arcade Inputs: Discrete binary keypresses made AI vehicles jerk left and right. Capping neural activations with the (\text{Tanh}) function and tuning lateral momentum decay created realistic analog steering grip.
- Relative Scrolling Collision Mathematics: Keeping the player anchored at (Y=560) while scrolling traffic downwards meant speed differentials directly affected distance metrics. We had to normalize all spatial distance inputs ((\Delta x, \Delta y)) relative to maximum highway dimensions for stable neural matrix operations.
🏆 Accomplishments that we're proud of
- Zero Heavy ML Framework Dependencies: Built a complete, performant neural network and genetic algorithm framework powered entirely by NumPy matrix operations.
- Emergent Pursuit Tactics: Watching the AI organically discover tactical behaviors—such as tailgating for drafts, lane-flanking, and cutting off player escape routes—after just 5 to 10 generations.
- 60 FPS Real-Time Execution: Achieved seamless 60 FPS gameplay with instant live inference and zero frame drops during population evolution.
🎓 What we learned
- Neuroevolution is ideal for real-time continuous control: For fast-paced 2D games, Genetic Algorithms can converge significantly faster than gradient-based Reinforcement Learning (Q-learning/PPO) without needing complex loss function tuning.
- Fitness function design is critical: Rewarding spatial alignment and close proximity created much more convincing human-like pursuit curves than simply scoring speed or raw catch time.
🚀 What's next for neural network pygame
- Multi-Agent Swarm Pursuit: Scaling the engine to support multiple AI pursuers that coordinate tactical box-in maneuvers.
- 360° Raycast LIDAR Sensors: Replacing spatial telemetry metrics with dynamic raycasting so the AI can actively detect and overtake ambient traffic obstacles.
- WebAssembly (Pygbag) Deployment: Compiling the Pygame and NumPy runtime into WebAssembly so users can battle evolving AI directly in their web browser.
- Circuit & Arena Tracks: Expanding from linear scrolling highways to full 2D circuit tracks with lap-by-lap learning.
Log in or sign up for Devpost to join the conversation.