What you need to do if you want to do it this way is to convert the 'maze' into a graph (the comp.sci. version). As to not force minimization of this graph, simply construct it by looking at each open space on the map, and creating graph connections between that space and open spaces, using some id strict like "5,6" to represent the X=5, Y=6 space.
Then you simply use the shortest graph distance algorithm from the node where the mouse is to where the node where the cheese is. This will not only find you the shortest route (and thus avoid dead-ends), but will also determine if the cheese is unreachable.
Note however that this sort of 'violates' the spirit of the problem in that you've suddenly given the mouse full understanding of the maze. A somewhat better solution in the sense of keeping the mouse sufficiently clueless is to have it be able to backtrack to the last decision point if it reaches a dead end, and to select a new route from that point. If the mouse reaches it's starting point and has exhausted all paths from it, it should conclude that the cheese is unreachable (but again, this method will search the entire maze, so it will have lots of dead ends).
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.