I get no output for this at all... (after fixing some typos -- you should cut and paste working examples when you post).
I haven't looked too hard at it, but I do notice you are using a PRNG in there...
Don't.
The solution to this problem is deterministic.
The idea is weird at first glance, but simple:
If someone trying to solve the maze chooses a random direction to walk at each juncture (every time he is forced to turn because he hit a wall), the possibility of exiting should
always exist.
Let's consider a few scenarios:
(1)
Our first scenario we start at the solid brick and follow in one direction until forced to turn.
It is simple enough: we have two possible directions to choose, and at each turn two again -- one of which is back the way we started. No matter how long we spend going back and forth on the top row, the instant we "randomly" turn south we will walk into an exit.
# # # # # # # # # # # #
# # ┌───█─────┐ # #
# │ # # │ #
# │ # E # #
# │ # # #
# │ #
# # E E # # #
# # # # # # # # # # # # |
(2)
Our second scenario is similar. The only difference is that at each juncture we have more decisions. At no point, however, does any decision lead us into a path where we cannot eventually find our way to an exit.
# # # # # # # # # # # #
# # ┌───────┬─┐ # #
# │ # # │ │ #
# │ # ┌───█─E # #
# │ │ │ # # #
# │ │ │ #
# # E───┴───┴─E # # #
# # # # # # # # # # # # |
(3)
Our final scenario starts us at a bad position.
While it is very similar to our last starting position -- it does indeed present the random possibility of finding an exit -- it
also presents the possibility of wandering off the the left side of the board, where, as we can see, there is no escape. (Remember, in order to turn, you must first walk into a wall. So it is possible to get there, but unless you "randomly" turn immediately back the way you came, you cannot get out.)
# # # # # # # # # # # #
# ║ # ┌───────┬─┐ # #
# ║ │ # # │ │ #
# ║ │ # │ E # #
# ╟─────┬─────┤ # # #
# ║ │ │ │ #
# ║ # E─█─────┴─E # # #
# # # # # # # # # # # # |
You can check in any time you like, but you can never leave.
In order to find those spots on the board where the only possibility is successful exit, you
must follow
every path available from your start position.
Using the first example, we start at (1,5).
Then we follow
all possible directions.
To the west, we go to (1,3), then down to (6,3) which is an exit.
To the east, we go to (1,8), then down to (3,8) which is also an exit.
Having followed every path from every juncture we have verified that
all paths lead to exit.
Hopefully this has suggested something to you:
TL;DR:
In order to solve this, you should be thinking of your maze as a
graph and use a search algorithm on it (DFS or BFS, either will do):
• If
all the leaves in your search yield exits, then your start position is golden.
• If
any leaf in your search yields a dead end, then your start position is no good.
This is a fairly brute-force solution. In more advanced algorithms courses you can learn about stuff that can do it more efficiently, but don't worry any about that...
Hope this helps.