DIY : Automatically Generating and Printing Mazes with Raspberry Pi
Solving mazes is always a lot of fun, but designing and drawing them by hand is pretty labor intensive. You have to make them challenging but still fun, and that’s a time-consuming proposition. So, when Engineerish (Mattias Jahnke) needed to churn out new mazes for his nephew to solve, he turned to technology. What he came up with is a maze generator that runs on a Raspberry Pi, and automatically creates and prints new mazes at the touch of a button.
The maze games that you find in newspapers and on the back of cereal boxes may look simple, but they actually take quite a bit of planning if they’re drawn by hand. They, ideally, need to be designed with just one real solution, and a number of routes that look convincingly like possible solutions. To generate them automatically, Jahnke used a recursive backtracking algorithm. That algorithm uses a limited trial-and-error approach to quickly find solutions in order to build a “map” of the maze.
The algorithm is written in Python, and the script runs on the Raspberry Pi whenever an arcade button is pressed. Once it has generated the maze, a thermal printer — like what is used for receipts at a cash register — is used to put the solvable puzzle onto paper. The entire process happens quickly enough to keep children occupied, and Jahnke was even gracious enough to provide the code so you can build your own!