ScratchData LogoScratchData
Back to QX_'s profile

Recursive Maze Generator and Solver

QXQX_•Created April 1, 2021
Recursive Maze Generator and Solver
2763
2294
102079 views
View on Scratch

Instructions

Press the Green Flag and type in a maze size (it must be between 5 and 275). Turbo mode is recommended for large maze sizes, but not required. Press spacebar to begin recursively solving To activate turbo mode, Shift+Click the Green Flag

Description

There are numerous ways to generate and solve mazes, and recursive backtracking is one of them. A recursive method calls itself, as opposed to an iterative method which goes through a loop until a certain condition is met. The algorithm in this project works by starting the method in the middle cell (if you view the maze as an matrix). For each cell, a random direction is picked, and the adjacent cell will be checked to see if it has already been visited. If it has been visited, then a different cell will be picked. If all adjacent cells are visited, then it will go back in the stack to the most recent cell that has an adjacent unvisited cell. After there are no more adjacent cells that haven't been visited, the method is finished. Solving the maze is almost entirely identical, but with the stopping condition being that it has reached the end cell.

Project Details

Project ID510068047
CreatedApril 1, 2021
Last ModifiedJanuary 14, 2023
SharedApril 2, 2021
Visibilityvisible
CommentsAllowed