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
|
void run(int a,int b, bool& state){// (x,y,pervious direction)
// display row col grid
// check if surrounding spaces are the exit,if so return number of spaces traveled
// check if any openings up,right,bottom,down
// if direction is open then run in that direction with new position
// if all directions closed then trapped at memory location
maze[a].at(b) = '@';
cout << " Row: " << a << " Col: " << b << endl;
cout << " 0123456789" << endl;
for(int i = 0; i < 10; i++){
cout << i << maze[i] << endl;
}
if(a != 0){
if(maze[a--].at(b) == 'E'){state = true;return;}}
if(b != 9){
if(maze[a].at(b++) == 'E'){state = true;return;}}
if(a != 9){
if(maze[a++].at(b) == 'E'){state = true;return;}}
if(b != 0){
if(maze[a].at(b--) == 'E'){state = true;return;}}
system("pause");
if(a != 0){
if(maze[a--].at(b) != '+' && maze[a--].at(b) != '@' && a != 0){run(a--,b,state);}}
if(b != 9){
if(maze[a].at(b++) != '+' && maze[a].at(b++) != '@' && b != 9 && state == false){run(a,b++,state);}}
if(a != 9){
if(maze[a++].at(b) != '+' && maze[a++].at(b) != '@' && a != 9 && state == false){run(a++,b,state);}}
if(b != 0){
if(maze[a].at(b--) != '+' && maze[a].at(b--) != '@' && b != 0 && state == false){run(a,b--,state);}}
return;
}
| |