Advertisement
Guest User

Untitled

a guest
Nov 30th, 2011
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. int dir = 4;
  2.  
  3. bool visited[Max_Maze][Max_Maze][dir];
  4.  
  5.  
  6. for (row = 0; row < size; ++ row)
  7. {
  8. for (col = 0; col < size; ++ col)
  9. {
  10. for (dir = 0; dir < 4; ++ dir)
  11. {
  12. visited[row][col][dir]=false;
  13. }
  14. }
  15. }
  16.  
  17. bool notSolved = true;
  18. int path = 0;
  19. row = 0;
  20. col = 0;
  21.  
  22. rowStack.push(row);
  23. colStack.push(col);
  24.  
  25. while (notSolved){
  26.  
  27. //from perspective of person looking at maze on screen
  28. if (((row-1)>0)&&(maze[row - 1][col] == 0)&&(visited[row][col][0]==false)){//if that space is not out of bounds and if you can go up
  29. visited[row][col][0] = true; //and you have not gone in that direction yet, go up
  30. row--;
  31. rowStack.push(row);
  32. colStack.push(col);
  33. path++;
  34. cout << "UP" << path << endl;
  35. }
  36. else if (((col+1)<size)&&(maze[row][col + 1] == 0)&&(visited[row][col][1]==false)){//else if you can go right, go right
  37. visited[row][col][1] = true;
  38. col++;
  39. rowStack.push(row);
  40. colStack.push(col);
  41. path++;
  42. cout << "RIGHT" << path << endl;
  43. }
  44. else if (((row+1)<size)&&(maze[row + 1][col] == 0)&&(visited[row][col][2]==false)){//else if you can go down, go down
  45. visited[row][col][2] = true;
  46. row++;
  47. rowStack.push(row);
  48. colStack.push(col);
  49. path++;
  50. cout << "DOWN" << path << endl;
  51. }
  52. else if (((col-1)>0)&&(maze[row][col - 1] == 0)&&(visited[row][col][3]==false)){//else if you can go left, go left
  53. visited[row][col][3] = true;
  54. col--;
  55. rowStack.push(row);
  56. colStack.push(col);
  57. path++;
  58. cout << "LEFT" << path << endl;
  59. }
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement