This project implements an DFS algorithm to solve randomly generated mazes in Python
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
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
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
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