Update the Maze Class
00:00
Updating the Maze Class. At this point, the serializer
module doesn’t depend on the Maze
class anymore because there are no direct references to it.
00:10
You can safely update your maze
model as a consequence.
00:40
With this class method, you can .load()
squares from the specified path and turn them into a new Maze
instance.
00:59
Conversely, by calling .dump()
on an existing Maze
object, you’ll dump its squares along with the necessary metadata to a given path.
01:15
On-screen is an example of the Maze.load()
class method in action, which loads your miniature test maze.
01:37
Now, you only need to import one symbol from the maze_solver
package to work with mazes stored in files. The deserialized object’s attribute values confirm that you successfully loaded the maze.
01:52
You can also check if you correctly guessed which squares are the entrance and exit of the miniature maze. So with that in place, why not go ahead and try loading a more challenging maze from the supporting materials? For example, the labyrinth.maze
has 896 squares arranged in 32 rows and 28 columns.
02:19
You can preview it in your web browser by running the code seen on-screen in the REPL. Make sure that you specify the right path to the file and run the code from a virtual environment that has the maze_solver
package installed.
02:36 This is the maze you should see on-screen. This maze was assembled from satellite and aerial photos of a real world labyrinth, which can take as long as forty-five minutes to complete on foot.
02:50 Can you find the way out to this maze by looking at it? While there are no enemies, the maze is still quite tricky. It would, of course, be better to get Python to solve this maze and indeed any others you have stored in your binary format.
03:05 So, in the next section of the course, you’ll look at how you can do that by implementing graph representation of mazes and then solving them with NetworkX.
Become a Member to join the conversation.