EXP-02 · reinforcement learning
An agent that crosses a minefield
A Frozen Lake–style environment with bombs built in Gymnasium, and a DQN agent that learns to reach the goal from any cell without stepping on a bomb.

Question
Can a DQN agent learn a 7×7 minefield with tunnels, starting from any cell, with no map?
Problem
Design the environment (states, actions, rewards) and train an agent to reach the goal from 41 possible starts while avoiding 5 bombs.
Data
A custom Gymnasium environment: a 7×7 grid (states 0–48), the goal at cell 48 (+100), 5 bombs (−100), two teleporting tunnels (3 → 28 and 36 → 20), and −1 per step to reward short paths. The agent starts on any of the 41 valid cells.
Method
A custom Gymnasium environment, a random-player baseline, a Stable-Baselines3 DQN trained for 200,000 steps and evaluated over 1,000 games, with a visualization of the learned policy.
Result
Success rose from 7.1% (random) to 100% over 1,000 games, with zero bombs hit, and average steps dropped from 14.7 to 5.4.
What I learned
A −1 reward per step taught it the shortest safe path: 14.7 → 5.4 steps.
Stack
- Python
- Gymnasium
- Stable-Baselines3
- DQN
- NumPy
- Matplotlib
Context
Course: Expert Systems · 2026