Rolling Ball Maze Puzzle
Navigate a rolling ball through procedurally generated mazes using keyboard or device tilt. 20 levels of increasing difficulty with physics-based movement.
About
Maze-solving is a graph traversal problem with direct applications in robotics path planning, VLSI routing, and network topology. This tool generates perfect mazes using a Depth-First Search recursive backtracker, guaranteeing exactly one solution path between any two cells. The ball obeys simplified Newtonian mechanics: acceleration a is applied from user input, velocity v accumulates with a friction coefficient ΞΌ β 0.92 per frame, and position updates via Euler integration. Wall collisions use axis-aligned bounding box checks against the grid. The maze grid scales from 7Γ7 at level 1 to 25Γ25 at level 20. Solving time is tracked per level. Note: device tilt controls require a gyroscope-equipped device and HTTPS context. Desktop users rely on arrow keys or WASD.
Formulas
The ball position is updated each frame using Euler integration. User input (arrow keys or device tilt) provides an acceleration vector that is scaled and added to velocity. Friction decays velocity each frame to prevent infinite sliding.
Where v is velocity (px/frame), a is acceleration from input (0.5 px/frameΒ²), dt is the time step (normalized to 1 at 60fps), and ΞΌ is the friction coefficient (0.92). A lower ΞΌ makes the ball stop faster. Collision detection checks the ballβs bounding circle against each wall cell in the grid. If the ball center enters a wall cell, it is projected back to the nearest edge and the velocity component normal to that wall is zeroed.
The maze is generated via recursive backtracking (randomized DFS). Starting from cell (0,0), the algorithm visits random unvisited neighbors, carving passages. This produces a perfect maze: every cell is reachable, and there is exactly one path between any two cells. The start is placed at the top-left and the exit at the bottom-right.
Reference Data
| Level | Grid Size | Cell Count | Est. Path Length | Target Time (s) | Difficulty |
|---|---|---|---|---|---|
| 1 | 7Γ7 | 49 | 15 - 25 | 15 | Beginner |
| 2 | 8Γ8 | 64 | 20 - 30 | 20 | Beginner |
| 3 | 9Γ9 | 81 | 25 - 40 | 25 | Beginner |
| 4 | 10Γ10 | 100 | 30 - 50 | 30 | Easy |
| 5 | 11Γ11 | 121 | 35 - 60 | 35 | Easy |
| 6 | 12Γ12 | 144 | 40 - 70 | 40 | Easy |
| 7 | 13Γ13 | 169 | 50 - 85 | 45 | Medium |
| 8 | 14Γ14 | 196 | 55 - 95 | 50 | Medium |
| 9 | 15Γ15 | 225 | 60 - 110 | 55 | Medium |
| 10 | 16Γ16 | 256 | 70 - 125 | 60 | Medium |
| 11 | 17Γ17 | 289 | 80 - 140 | 70 | Hard |
| 12 | 18Γ18 | 324 | 85 - 155 | 75 | Hard |
| 13 | 19Γ19 | 361 | 95 - 170 | 80 | Hard |
| 14 | 20Γ20 | 400 | 100 - 190 | 90 | Hard |
| 15 | 21Γ21 | 441 | 110 - 210 | 95 | Expert |
| 16 | 22Γ22 | 484 | 120 - 230 | 100 | Expert |
| 17 | 23Γ23 | 529 | 130 - 250 | 110 | Expert |
| 18 | 24Γ24 | 576 | 140 - 270 | 115 | Expert |
| 19 | 25Γ25 | 625 | 150 - 300 | 120 | Master |
| 20 | 25Γ25 | 625 | 160 - 320 | 130 | Master |