David OgunmolaDavid Ogunmola.
Projects/autonomous-snake-agent
Deep Q-Learning · Deep Q-Learning trained to play Snake

Autonomous Snake Game Agent

Applied Deep Q-Learning with Python and Pygame to train an agent that improves through reinforcement learning — achieving high scores autonomously.

Deep Q-LearningPygameRLPython
View on GitHub

Reinforcement Learning & Pathfinding

This project reimagines the classic Snake Game by teaching an agent to autonomously navigate, collect food, and avoid collisions using a suite of Reinforcement Learning algorithms and Graph Theory fallbacks.

Training Algorithms

  • Deep Q-Networks (DQN): Implemented to generalize across the massive state space, significantly boosting convergence over baseline Q-Learning.
  • Double DQN: Addressed Q-value overestimation, becoming the most stable and performant driving model.

Fallback Strategies

To prevent the agent from trapping itself in late-game scenarios, I integrated hard-coded safety mechanisms:

  • Hamiltonian Cycle: Generated using Prim's algorithm to guarantee survival indefinitely.
  • BFS (Breadth-First Search): Used as a deterministic mid-game trajectory shortcut.

Results

The model performed exceptionally well on a 400×400 grid (20×20 cells), utilizing Double DQN alongside safety fallbacks to achieve highly strategic, automated gameplay.

Back to all projects