Creative Coding for Surpac - Maze Generation

In this creative coding post, I want to look at maze generation and solving. I had seen an algorithm called A* (A-Star) previously and it looked pretty interesting however, trying to write the macro from scratch was just too time consuming so credit to Grok AI for supplying the bulk of the code to do this and the image above. 

Why use A*

A* is a great maze solver because;

  1. It's Goal-Oriented.  It doesn't just randomly walk through the maze, instead A* uses the "h" score (estimated distance to the goal) to focus on moves that seem to get closer to the end.  This makes it faster than blindly checking every path.
  2. It Finds the shortest path.  By keeping track of the actual distance traveled (g) and always picking the lowest total score (f), A* ensures it finds the shortest possible route.
  3. It's flexible. A* will work for any maze size, though the larger the maze, the longer the compute time to generate and solve the maze.

What can be learned in this macro?

There's a lot of code in this macro that could be reused for other projects.  On top of that, you can learn about;

  1. Scl Layer creation and manipulation
  2. Scl String, Segment and point creation and manipulation
  3. GUIDO form creation
  4. TCL Lists
  5. TCL Dictionaries
  6. Creating and calling TCL Procedures

to name just a few of the commands used. 

What does the macro generate?

Why, mazes of course.  Fully complete, and fully solved mazes.  Every time you run the macro, a new unique maze is drawn.  If you want a bit of a challenge, I find the 70w by 40h maze (fits nicely on an A4 landscape piece of paper) is a good way to go.  The maze and solution are different string numbers so just delete the solution string and print it out. 

As always, the macro is available at the bottom of this post so please download, experiment and leave a comment to let me know if you enjoyed this post.

 

 

 

Maze generation Macro