Calculate probabilty to escape the maze
First of all, note that you should use pseudo-code in your question to make it readable by anyone.

You cannot treat this problem by just listing possible ends and give them equal probability. Consider this trivial case with no tunnel:

%AO*

the frog does not have a total 50 % to escape. On first move it has 50 % to go left to exit and 50 % to go right. But if it goes right it has 50 % to die on the mine and 50 % to come back on initial cell. Finally you build the series:


to exit $\sum_n \frac{1}{2^{2n+1}} = 2/3$
to die  $\sum_n \frac{1}{2^{2n+2}} = 1/3$


Of course finding the series expression can be very complicated on hard mazes. So how to solve this problem ? You can for example use a dynamic programming solution.

The sub-problem is having the probabilities for the frog to be on any cell after the $k^{th}$ move, what are the probabilities after the $(k+1)^{th}$ move ? These probabilities also contain exit and death.

So let's take again the small example %AO*, indexing the cells 1 to 4 from left to right.


at $k=0$, the frog is on cell 2 so $P(2) = 100 \%$,
at $k=1$, the frog moves left or right, so $P(exit) = 50\%$, $P(3)=50\%$,
at $k=2$, $P(exit) = 50 \%$, $P(2) = 25 \%$, $P(dead)=25\%$


ans so on, until $P(exit) + P(dead)$ is sufficiently close to 100 % for the precision you need.

Due to tunnels or even from start position, there may be some cells unable to reach a mine, an exit or any of them (as your first example). You should first investigate this, any cell that cannot reach an exit shoud be considered as a mine. And a cell that cannot reach a mine but can reach an exit should be considered as an exit. This will prevent any infinite loop and save some time.