There is a universal solution to getting out of a maze...

Firstly, all junctions can be broken down into a number of T-junctions. Take this four way junction:

```  # #
# #
### ###

### ###
# #
# #
```
which is identical to
```  # #
## ##
##   ##
O
##   ##
## ##
# #
```
were it not for the central pool.

This means that any path between any two points can be converted into a number of lefts and rights. (To go straight on in this example, you turn left then right then left).

Next, you should estimate the depth of the maze. This is the bailout factor, after which you give up on a particular path and try another. If this is not high enough you won't get out of the maze. This is the lowest number of lefts and rights that will get you out of the maze.

Start wherever you are. Then count, in binary, from 0 to 2bailout-1. (That's going to be in the order of a thousand for a small maze, up to about a couple of million for a complex one. You got the time, I take it...)

Then follow the path, taking 0's to be left-turns and 1's to be right-turns. If you reach the end of the binary string, retrace your steps (the opposite of your path before) and try the next one.

YMMV, but it's going to be quite excessive anyway...