Rat in a Maze — DFS Backtracking with a Visited Matrix

The rat explores from the top-left cell to the bottom-right, trying D, L, R, U in order. Watch the path stack grow, cells get marked visited, and dead ends trigger the un-mark backtrack.

step 0

Maze & rat exploration

wall rat (current) visited (on trail) found path dead end
Cells explored: 0 · Backtracks: 0

Path stack (current trail)

(empty — rat at start)
Recursion stack (top = current cell):
Status: searching…
Press Step to begin. The rat runs DFS: it marks each cell visited, tries directions D, L, R, U, and un-marks a cell when it backtracks out of a dead end.
Self-contained visualization. Directions tried in order D, L, R, U, so the first path found is the lexicographically smallest. Marking a cell adds it to the current trail; the un-mark on backtrack removes it so other branches may reuse it. See junior.md and professional.md for the visited-matrix invariant (visited set = current recursion stack).