User Rating 0.0 β˜…β˜…β˜…β˜…β˜…
Total Usage 0 times
Category Puzzles
Level 1
Time 0.0s
Best
Stars ☆☆☆
Rolling Ball Maze

Navigate the ball to the green exit. Use arrow keys, WASD, or tilt your device.

Level 1 / 20
Is this tool helpful?

Your feedback helps us improve.

β˜… β˜… β˜… β˜… β˜…

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.

maze puzzle rolling ball tilt maze ball maze game labyrinth puzzle maze generator physics puzzle

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.

vnew = (vold + a β‹… dt) β‹… ΞΌ
xnew = xold + vnew β‹… dt

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.

Grid size = 7 + (level βˆ’ 1)

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

LevelGrid SizeCell CountEst. Path LengthTarget Time (s)Difficulty
17Γ—74915 - 2515Beginner
28Γ—86420 - 3020Beginner
39Γ—98125 - 4025Beginner
410Γ—1010030 - 5030Easy
511Γ—1112135 - 6035Easy
612Γ—1214440 - 7040Easy
713Γ—1316950 - 8545Medium
814Γ—1419655 - 9550Medium
915Γ—1522560 - 11055Medium
1016Γ—1625670 - 12560Medium
1117Γ—1728980 - 14070Hard
1218Γ—1832485 - 15575Hard
1319Γ—1936195 - 17080Hard
1420Γ—20400100 - 19090Hard
1521Γ—21441110 - 21095Expert
1622Γ—22484120 - 230100Expert
1723Γ—23529130 - 250110Expert
1824Γ—24576140 - 270115Expert
1925Γ—25625150 - 300120Master
2025Γ—25625160 - 320130Master

Frequently Asked Questions

The algorithm starts from a single cell and uses depth-first search to visit every cell exactly once, carving passages between adjacent cells. Because every cell is visited, the resulting maze is a spanning tree of the grid graph - meaning exactly one path exists between any two cells. The start and exit are always connected.
Each frame, velocity is multiplied by the friction coefficient ΞΌ β‰ˆ 0.92. This exponential decay means the ball retains 92% of its speed per frame. At 60fps, the ball loses about 99.5% of its velocity within 1 second of releasing input. Reducing ΞΌ to 0.85 would make the ball feel "grippier" but less realistic for a rolling ball on a smooth surface.
Device tilt requires the DeviceOrientation API with a gyroscope sensor. Most modern smartphones support this. iOS 13+ requires explicit user permission via a button tap (cannot auto-request). Some tablets and older Android devices may lack gyroscope hardware. The game always provides on-screen directional buttons as a fallback.
Velocity is clamped to a maximum of 5 pixels per frame to prevent tunneling (passing through thin walls). Additionally, the collision check tests the ball's projected position against all neighboring grid cells within a 2-cell radius, resolving overlaps by axis-aligned projection. This is sufficient for the cell sizes used (minimum ~16px at level 20).
Target times are estimated from the average BFS shortest-path length for each grid size, multiplied by an empirical factor of approximately 0.4 seconds per cell traversed. This assumes a skilled player who knows the path. First-time solvers typically take 2-4Γ— the target time due to dead-end exploration.