Advertisement
Guest User

Untitled

a guest
Nov 29th, 2011
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. bool notSolved = true;
  2.         int path = 0;
  3.         row = 0;
  4.         col = 0;
  5.  
  6.         rowStack.push(row);
  7.         colStack.push(col);
  8.         while (notSolved){
  9.  
  10.         //(from perspective of person looking at maze on screen)
  11.         if (maze[row--][col] == 0){//if you can go up, go down
  12.         rowStack.push(row);
  13.         colStack.push(col);
  14.         path++;
  15.         }
  16.         else if (maze[row][col++] == 0){//else if you can go right, try to go right
  17.         rowStack.push(row);
  18.         colStack.push(col);
  19.         path++;
  20.         }
  21.         else if (maze[row++][col] == 0){//else if you can go down, try to go down
  22.         rowStack.push(row);
  23.         colStack.push(col);
  24.         path++;
  25.         }
  26.         else if (maze[row][col--] == 0){//else if you can go left, try to go left
  27.         rowStack.push(row);
  28.         colStack.push(col);
  29.         path++;
  30.         }
  31.  
  32.             if(row == (size - 1) && col == (size - 1)){//if we reached an exit
  33.                 cout << "Solution Path:" << endl;
  34.                 for (int i = 0; i < path; i++){
  35.                     cout << "row:" << rowStack.top() << " col:" << colStack.top() << endl;
  36.                     rowStack.pop();
  37.                     colStack.pop();
  38.                 }
  39.             notSolved = false;
  40.             }
  41.         }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement