Maze solving with path drawing
Show older comments
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:
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 tell me "A", "B", "C" or "D"? I already thought about this for a long while, but found no solution. One of the solutions I thought about was, in pseudocode:
if CertainCoordinate = red pixel
return A
Whereas CertainCoordinate Could be the unchangeable coordinate 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?
Secondly, I was trying to solve the second ScreenShot's problem, it's not really a problem since it finds the exit, but it goes berserk afterwards, so I thought of coloring the two white bands (with the letters) as black bands, this way MatLab wouldn't be confused and think those are walls. Would this be a viable solution?
Thanks in advance!
3 Comments
Image Analyst
on 2 Mar 2013
See Professor Cris Luengo's comment for my maze - he improved upon it.
Image Analyst
on 2 Mar 2013
message = sprintf('Hey User!\nI Actually found the answer,\nit's %f!', B);
uiwait(helpdlg(message));
Image Analyst
on 2 Mar 2013
You could have a list of what pixels are exits. Then label the path(s) and call regionprops. If a pixel coordinate on the labeled blob is on the "exit list" and "entrance list" then that path (blob) is a solution. You can get the coordinates from the 'PixelList' measurement of regionprops().
Accepted Answer
More Answers (0)
Categories
Find more on Labyrinth problems in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!