DigDug AI
about
This project implements an autonomous agent that plays a custom clone of the classic arcade game Dig Dug, developed for a university Artificial Intelligence course. The system is split into three independent processes: a game server running the core loop and emitting state over WebSockets, a Pygame-based visual renderer, and the AI client itself. The agent is fully decoupled from the game engine, communicating exclusively through a JSON/WebSocket protocol — it receives the full game state each tick and responds with a single key press.
At the core of the agent is an A* pathfinding implementation using a Manhattan distance heuristic, with two distinct cost functions: one for normal navigation that mildly penalizes proximity to enemies and rocks, and one for flee mode that aggressively avoids danger. A dynamic danger map is recalculated every tick, marking tiles around each enemy as high-cost based on enemy type, position, and direction of travel — Fygar enemies, which breathe fire, receive extended danger zones to account for their reach.
The agent's behavior is governed by a simple state machine: when the nearest threatening enemy is more than 3 tiles away, it enters chase mode, pathing to a position behind the enemy relative to its movement direction before firing its rope weapon; when an enemy closes to within 1 tile, it switches to flee mode, pathing toward the nearest corner. Enemy targeting prioritizes surface-level threats, which are considered more dangerous due to their proximity to the player's spawn. An unstuck mechanism detects when the agent hasn't moved in 20+ frames and forces a full path recalculation to escape loops.
Internally, the agent maintains its own world-state representation independent of the game engine's, using IntFlag bitflags (EMPTY, WALL, ROCK, POOKA, FYGAR) to encode tile state in a single integer, enabling fast bitwise checks for passability and enemy detection within the game's 10 FPS loop.
highlights
- ·Implemented A* pathfinding with Manhattan distance heuristic and dual cost functions for safe navigation vs. evasion
- ·Built a dynamic danger map updated every tick, weighting tiles by enemy type, position, and direction of travel
- ·Designed a chase/flee behavioral system with surface-enemy prioritization and stuck-state recovery
- ·Achieved a top grade of 16.5-16.6/20 for the agent's design and performance
stack
Core
AI
Communication