Skip to content

Depth-first search recursive maze solver using Python and Tkinter for an interactive GUI

Notifications You must be signed in to change notification settings

ASproson/maze_solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maze Solver

This project implements an DFS algorithm to solve randomly generated mazes in Python

Demonstration

Animation

Animation2

Technical Walkthrough

graphics.py

Here we establish the Window class which is our GUI instance. We then draw to that Canvas using various Lines that are drawn from Point to Point

cell.py

This file then makse use of the Line and Point methods to both draw all the cells in the grid and the 'solving' line. Note the use of wall_color(self.has_right_wall), this is what we use to 'color' a line to determine whether or not it has a wall. To be more specific a wall is always drawn regardless, but by changing its color to white it provides a better visualization

maze.py

This creates the grid and generates the number of cells required based on the specified grid height and width. The animate() method is what provides the 'drawing' animation by calling redraw(), which allows us to visualize both the initial grid and the grid updates as the algorithm solves the maze

The break and solve methods are the core of the DFS algorithm, and calculate which directions are available for us to move in (up/down/left/right), and which walls to 'break down' as a result (re-color is a more description based on cell.py)

The rows are specified as i, with columns denoting j. To move up we have to subtract from i (rows) so that we select the row above, to move left we have to subtract of j (cols). The main technical challenge here was ensuring this calculation always remained within the index bounds of list

main.py

Here we pass the core parameters such as number of rows/columns, and the overall height of the canvas we would like to draw to. Additionally, there is a seed that we can pass that fixes the randomization to a specific pattern, which I predominately used for testing purposes

About

Depth-first search recursive maze solver using Python and Tkinter for an interactive GUI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages