If you give the mouse a "facing" direction (say, north = 0, west = 1, etc) then you can do something like the following:
Code:
"Feel" the wall to the left of the mouse, depending on his direction
IF (WallIsThere == false)
{
Rotate Counter-Clockwise
Move Forward
}
ELSE
{
Check in front of the mouse
IF (WallInFront == false)
{
Move Forward
}
ELSE
{
Rotate Couter-Clockwise
}
} |
Anytime you call the "Move Forward" function, you toggle the current floor marker (. or +), then move your ghosted mouse to the next tile. This will "clear" the marker if you hit a dead end. The mouse will try all possible places (luckily there are no loops..).
Of course, you'll probably end up with diagonals where the mouse tested a dead-end. In your example, here's the output:
Code:
# # # # # # # # # #
# . # M + . # . . #
# . # # + # # # . #
# . . . + + . . . #
# # # # . # + # # #
# . . . . # + # C #
# # # # # # + # + #
# . # . . . + # + #
# . . . # . + + + #
# # # # # # # # # # |
This is easy to fix. Just scan the entire maze for "." tiles, and check the tiles surrounding it in the four compass directions. If you get 2 "+"'s, add a "+" to that period tile.
I'm going to run this in my head a few times to see if I can spot any errors in my logic..