I receive a stackoverflow error when performing this recursion. There is a pattern, it says this first once:
at MazeGui.move(MazeGui.java:79) which is line if(rigting.goal == true) {
and then it says the following two, and both of them are repeated for a very very long time in the output. The problem is happening here somewhere I'm just not sure what:
at MazeGui.move(MazeGui.java:89) which is line move(rigting.right, pos); //moves right
at MazeGui.move(MazeGui.java:107) which is line move(rigting.left, pos); //moves left
...
...
Am I missing a termination condition or something, is there some infinite recursion happening? I can't wrap my head around it, completely lost. Any help would be appreciated.
The code:
public boolean move(Maze rigting, int pos)
{
if (rigting.goal == true)
{
return true;
}
if (rigting.wallR != true)
{
pos += 1;
move(rigting.right, pos); //moves right
showLabel(pos);
return true;
}
if(rigting.wallD != true) //checks if there is a wall below
{
pos += 10;
move(rigting.down, pos); //moves down
showLabel(pos);
return true;
}
if(rigting.wallL != true) //checks if there is a wall on the left
{
pos -= 1;
move(rigting.left, pos); //moves left
showLabel(pos);
return true;
}
if(rigting.wallU != true) //checks if there is a wall above
{
pos -= 10;
move(rigting.up, pos); //moves up
showLabel(pos);
return true;
}
return false;
}