I have to write a code for a maze. I have already completed to core of it. Howev
ID: 3627460 • Letter: I
Question
I have to write a code for a maze. I have already completed to core of it. However, I can't get the backtracking portion done. It checks to see if there is a '.' in the current location if there is then move there. If it eventually reaches a deadend start over and try again with moves not already tried. I know I am missing a boolean variable or something. Can someone please help me?public boolean solveMaze(int x, int y)
{
maze1.createPath(x,y);//places an x on current location
mazeSolve=maze1.copyArray();//makes a copy of current array
if(x == endx && y == endy)//base case this is the exit
return true;
else if (mazeSolve[x+1][y]=='.')//moves down
{
solveMaze(x+1,y);
}
else if (mazeSolve[x][y+1]=='.')//moves right
{
solveMaze(x,y+1);
}
else if (mazeSolve[x-1][y]=='.')//moves up
{
solveMaze(x-1, y);
}
else if (mazeSolve[x][y-1]=='.')//moves left
{
solveMaze(x,y-1);
}
else{
maze1.removePath(x,y);//replaces 'x' with '.'
mazeSolve=maze1.copyArray();
}
return false;
}//end recursion