Creating and Navigating Mazes

RobotMagic allows you to create mazes, which various supported robots can navigate through, either by direct user input or by using their sensors. This blog post covers how to create mazes as well as a simple maze-solving AI for the Scribbler robot.

Creating Mazes

To create a maze in RobotMagic, you’ll need to create what’s called a maze string. This string represents the structure of the maze, so it’s important to get it right. If you don’t, the maze may come out slightly malformed. The maze string can seem overwhelming at first, so to get started here is an example of a maze string and the maze it generates.

Open this world before moving on so you can modify this maze string. You’ll notice that the maze string consists of various symbols. Below is a list of what each of the symbols mean:

  • ‘/\’: End of line. Put these at the end of every line within the maze string.
  • ‘+-+…’: Horizontal maze wall section. This is the pattern that you need to enter to render a horizontal maze wall.
  • ‘+ | +’ : Vertical maze wall section. This is the pattern you will need to enter to render a vertical maze wall.
  • ‘x’: Where the robot actor will be placed


Try to modify this maze string to remove one of the sections. If you’re feeling comfortable, see if you can make more major changes to the maze, maybe add an arm of one of the sides?

Once we’ve got a maze string, we can call the maze function to generate the maze. You should preferably do this in the configure function. The first parameter of the maze function is size, which is what defines the length and width of a maze section. For now, just set that to 20, but feel free to experiment later. The code below is the same as the code in the example world.


Scribbler Maze Solving AI

Now that’s we’ve got a maze with our Scribbler in it, let’s see if we can do something interesting. Let’s say we wanted the Scribble to solve the maze itself. There are many ways to do this, and the approach we are going to take is quite crude and isn’t actually guaranteed to solve the maze, but given enough time it will.

EXPLAIN CODE

While true (continuous get Scribbler) to do this

Overall, this code is going to continuously move the Scribbler forward until it gets close to a wall. Then there is a 50% chance of it rotating left or right 90 degrees and then attempting to move forward.

To explain why this isn’t guaranteed to solve the maze, let's say we had a situation where the Scribbler needed to turn right to progress, but every time it makes the decision to turn, it turns left. Since the change is 50%, it is technically possible for the Scribbler to never go right, but the chances of that becomes extremely small quickly, so you don’t need to worry.

To see the completed world, with a complex maze and our Scribbler ‘AI’, go here. Hopefully this overview/tutorial was helpful in introducing mazes. If you run into any issues with mazes or in general, please get in touch.