![]() |
Maze solver w/ stacks.
I have to make a maze solver using stacks. We can't use the stacks that come with java, and have to use this:
:
I also made a location class that we have to use :
The part where I am pretty much stuck at is on how to change the board. The main objective here is to have a maze and let the program solve it. It should keep track of its path and record its data and finish the maze. The maze is a 2-d array. :
The 0's translates to the paths available and 1's are walls. The stack class above is to be used to get across the maze. I don't want anyone to do it for me, but any guidance would be really appreciated. I'm just really confused on where to start here. |
Re: Maze solver w/ stacks.
The use of a stack gives you the ability to reject bad choices back to your latest bad choice. At that point, you choose an alternative path. You may follow that for a while and hit a dead-end again. Then you back up to the choice that lead to the dead-end and make a different choice.
In this way, you will eventually cover every choice. Obviously this will lead (eventually) to a solution (presuming a fair maze). There are other types of solutions. In a fair maze, if you choose to always go right (or left) at each choice, you will eventually emerge. You may have grown a beard in the process, or you may solve it quickly. If you want to find the absolutely shortest path, you can treat it as a graph problem and explore every possible path forward from any point in the maze where you currently stand. These paths will either terminate or return to some position you've previously occupied. This doesn't imply less work, it just implies that the maze is definitively solved for shortest path. You can also choose to make choices entirely randomly. The probability is high, but not certain, that you will reach the goal. |
| All times are GMT -5. The time now is 12:49 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC