boolean solved = false;
// while there are still paths to try and we have not yet encountered the finish
while ( !stack.isEmpty() && !solved ) {
GenState state = stack.remove(0); // pop
currentPosition = state.getPosition();
solutionPath.add(0, currentPosition);
if (currentPosition.equals(maze.getStopPosition())) {
solved = true;
}
dir = state.getDirection();
depth = state.getDepth();
if ( depth > currentCell.getDepth() ) {
currentCell.setDepth(depth);
}
currentCell = maze.getCell(currentPosition);