posted 13 years ago
Hi Rivosk. Problems like this become much easier when you first create some basic data structures to work with, which provide a few handy operations.
For instance, let's make a basic Labyrinth data type which provides methods to look at different directions, and to move into a new direction:
You now have a simple Labyrinth that has look(Direction) and move(Direction) methods. This should be plenty to implement some recursive method that finds all the paths to an exit.
Note that the trick here is that the move() method returns a new Labyrinth. You can call this method without worrying that your old labyrinth will be modified. In fact, the entire Labyrinth class here is immutable. This makes it very easy to work with.
As already has been mentioned, a tree is a good structure to represent paths with. If you don't want to use a tree, you can also use something like:List<List<Direction>>.