File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Maze Solving Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Maze Solving" Watch "Maze Solving" New topic

Maze Solving

tyler naughton

Joined: Mar 15, 2011
Posts: 3
Hi, I'm having trouble with my current program here. We are supposed to find a path out of a maze using a coordinate class. We have to create coordinates and then push them onto a stack. At the end we have to pop the stack to get the path coordinates. I am having problems backtracking in my while loop. I can get all the way to that but when it hits a dead end I can't figure out how to pop the stack and take the coordinates from the previous space and apply them to the loop. If anybody could help me out that would be great. I have included the coordinate class as well as some sample mazes. Thanks.

I think the problem is in this while loop (line 152)

Program Maze....

Coordinate class...

DynamicStack class
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That is a lot of code to go through and in all fairness I haven't. But I have a remark:

Do not catch ArrayIndexOutOfBoundsExceptions. Just ask the size of the array and operate in those bounds.
And if you really really really want to catch it then at least log it, otherwise you'll never know about the exception.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

In the class DynamicStack you declare 'head' to be of type 'Node'. What class is this 'Node'? You didn't add one to your code ..

I agree. Here's the link:
subject: Maze Solving
It's not a secret anymore!