Browsed by
Category: Python

How I refactored maze generating Python code and used advanced class features

How I refactored maze generating Python code and used advanced class features

Previously, I have created a maze generating code while learning Python. Later I enhanced it with animation and marking special cells. All of it was done in rush, to solve the problem. Now I spent some time improving the quality of the code by encapsulating code into classes, using “private” methods and fields and separating concerns. The exact steps I took can be viewed in the GitHub repository or read here.

Read More Read More

Recursive Backtracker maze – more features and animation with Matplotlib and Python

Recursive Backtracker maze – more features and animation with Matplotlib and Python

In the previous post, I generated a simple maze. I wasn’t sure the algorithm worked as intended unless I debugged or animated it. I chose the second option. I also added marking the beginning and end of the maze quest.

Read More Read More

Maze generation algorithm in Python – drawing and arrays

Maze generation algorithm in Python – drawing and arrays

There are plenty of maze generation algorithms, some are described here and here. I decided to use one to learn some Python. I chose Recursive Backtracker. You can find longer descriptions in both links, but briefly:

  • choose a random cell in the maze
  • walk in a random direction
  • when there is no possibility to walk farther, go back (backtrack) to find the first cell from which it is possible to proceed
  • the algorithm ends when there is no possibility to move from any cell

Read More Read More