This project implements a maze solver using Bounded Model Checking (BMC) with the Z3 Theorem Prover, wrapped in an interactive "Man vs Machine" web game.
src/: Core logicmaze.py: Maze generation (DFS) and representation.solver.py: SAT encoding for reachability using Z3.
app/: Flask Web Applicationapp.py: Backend API and server.templates/: HTML frontend.static/: CSS and JavaScript game logic.
tests/: Unit tests.
- Create a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate - Install dependencies:
pip install -r requirements.txt
- Start the Flask application:
python3 app/app.py
- Open your browser and navigate to:
http://127.0.0.1:5000/
- New Game: A random maze is generated. You are the Blue Square.
- Goal: Reach the Green Square.
- Controls: Use Arrow Keys to move.
- Man vs Machine:
- Try to solve it yourself!
- Click "Let Z3 Solve It" to see the AI find the optimal path.
- The AI path will be animated in Red.
- Compare your steps with the AI's optimal steps.
The solver uses Bounded Model Checking. It attempts to find a path of length
Variables:
- Play grid positions
$(x_t, y_t)$ at time steps$t \in [0, k]$ . - Constraints: Valid moves, obstacle avoidance, boundary checks.
The formula grows with UNSAT, we try SAT, we extract the model (path).
To improve performance for larger mazes, we implemented:
-
Symmetry Breaking (No U-Turns): A constraint
$\neg(pos_t == pos_{t-2})$ prevents immediate backtracking, pruning the search space. -
Heuristic Pruning (Distance Envelope): We enforce that at any step
$t$ , the Manhattan distance to the goal must be$\le (k-t)$ . This cuts off paths that wander too far to reach the goal within the remaining steps.