1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
int Maze::SolveMaze(char **a, int x, int y, int row, int col, int **b, int c)
{
if (x==row-1 && y==col-1)
{ if(a[col-1][row-1]!='.')//checks end of maze
{
cout<<"Maze has no end"<<endl;
return false;
}
else
a[col-1][row-1]='L';//Marks the path
b[col-1][row-1]=c++;//Marks the number of steps in a different array
cout<<"End found!"<<endl;
return true;
}
if ( y < 0 || y > row-1 || x < 0 || x > col-1 ) return false;//check if it's safe
if (a[y][x] != '.')
return false;
a[y][x]='L';// Marks path
b[y][x]=c;//Marks number of steps in a different array
c++;
if(SolveMaze( a,x,y-1, row, col, b, c)==true) return true;//North
if(SolveMaze( a,x,y+1, row, col, b, c)==true) return true;//South
if(SolveMaze( a,x+1,y, row, col, b, c)==true) return true;//East
if(SolveMaze( a,x-1,y, row, col, b, c)==true) return true;//West
a[y][x]='x';//unmarks if not in path, thinking maybe getting rid of this in another function might help
b[y][x]=1000;//Marks with 1000 in the int array
return false;
return false;
}
|