Download maze_solver.py and graph.py into the same directory. Install required packages (argparse, turtle, tkinter, random, time) using your system's package manager
./maze_solver.py [src_x] [src_y] [tgt_x] [tgt_y] [maze_ith_row]...
python3 maze_solver.py [src_x] [src_y] [tgt_x] [tgt_y] [maze_ith_row]...
- src_x: the x coordinate of the starting point
- src_y: the y coordinate of the starting point
- tgt_x: the x coordinate of the end point
- tgt_y: the y coordinate of the end point
- maze_ith_row: the ith row of the maze, represented by a string of 0's (empty cells) and 1's (blocked cells)
- the upper left hand corner of the maze corresponds to coordinate (0, 0)
- each row in the maze has to be of the same length
- all inputs are required
- To see help message:
- On Linux:
./maze_solver.py -h
- On Mac:
python3 maze_solver.py -h
A maze can be described as a two by two grid of blocked cells and empty cells with a starting point and an end point. We take in this information and parse it using the argparse package. We first convert the read in rows of the maze into a 2d array, then construct a graph with nodes representing cells and edges representing valid paths between cells. We then run a breadth first search on the graph to solve the maze, outputting coordinates along the path from the starting point to the end point. We use turtle to draw out the maze and animate the solution path. A random maze of the same dimensions is generated and drawn out 5 seconds after drawing out the solution of the input maze.