0
votes

I've been using the maze_solution function from Image Analyst http://www.mathworks.com/matlabcentral/fileexchange/27175-mazesolution for a while without problems. There are a few limitations: the maze has to be perfect and without circular paths.

That being said, it generally works very well when I test it, let me provide you with two examples of outputs:

maze-1 -> solution-1 (Clearly works well)

maze-2 -> solution-2 (Not so well)

Now let me put some rules that are not obvious about my mazes:

  1. There are no circular paths (there are some that are trapped in the walls, but no one that the the maze solver would run into).
  2. They begin always at the top left, and then there are four exits in the same coordinates every time.
  3. There is always only one exit.

So, what I would like to do is, let's consider the first screenshot. It works well and 'finds' the exit, is there any way to make mat lab pop up a messagebox (using msgbox(), for instance) and say something like "Hey user, I found the solution! It's A!"? I already thought about this for a long while, but found no way of doing this. One of the solutions I thought about was, in pseudocode:

if CertainCoordinate = red pixel
    return A

Whereas CertainCoordinate Could be the unchangeable coordinates (x and y) of A, B,C and D (Then I would use 4 'ifs'), but I don't really know how to implement even that. Any ideas or... something to point me in the right direction?

So, summarizing it: I have an algorithm that right now generates a red path to the exit (and I am open to better algorithms, if you have any suggestion) but my goal is to make matlab tell me what he found, instead of showing me in a image. So for instance, in the first image I would like it to open a MessageBox and say "Hey user! I found the exit, it's D!", instead of showing me the image with the red path on it. The problem is, I don't know how to teach MatLab 'where is D' and to make him recognize that he found 'D'. So, are there any suggestions on how to do that?

Thanks in advance!

1
They are variants of the 'connected components' algorithm using idea of graph coloring. You should refer to a standard algorithms textbook, maybe Steven Skiena, or by CLRS - Arcturus

1 Answers

0
votes

Suppose you have an image called maze aset of possible x coordinates of the exit and the corresponding y coordinates of the exit. Also you can check what color the maze solving program uses, lets say this is Red.

Now the solution is quite simple. First run the maze solver, then check the following

isRed = maze(x,y) == Red;
exitxCoordinates = x(isRed)
exityCoordinates = y(isRed)

This gives you the x and y coordinates. (If no solution is found they are empty). From here it should not be too hard to connect them to one of the letters that you specified.