Guest User

Untitled

a guest
Feb 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. //variables
  7. const int SIZE = 10;
  8. enum Values {space,wall, ext, X};
  9. Values maze[SIZE][SIZE];
  10. void createMaze();
  11. void displayMaze();
  12. bool robotMove();
  13. int numbermoves;
  14. int Cnum = 0;
  15. int Rnum = 0;
  16.  
  17. // main function
  18. int main () {
  19.  
  20. createMaze(); // give parameters
  21. displayMaze();
  22. robotMove();
  23.  
  24.  
  25.  
  26. }
  27. // functions
  28. void createMaze(int &Rnum,int &Cnum){
  29. for (int i= 0; i < 10; i++){
  30. for(int j = 0; j < 10; j++)
  31. maze [i][j] = wall;
  32. }
  33. for (int g = 0; g<10; g++){
  34. maze[0][g] = space;
  35. }
  36. for (int h = 0; h<10; h++){
  37. maze[h][h] = space;
  38. }
  39. for (int z = 0; z< 10; z++){
  40. maze[2][z] = space;
  41. }
  42. for (int r = 0; r<10; r++){
  43. maze[6][r] = space;
  44. }
  45. maze [4][0] = ext;
  46. maze [7][6] = ext;
  47. Rnum = 0;
  48. Cnum = 0;
  49. maze[Rnum][Cnum] = X; // starting position of X
  50.  
  51. }
  52. void displayMaze(int Rnum, int Cnum){
  53.  
  54.  
  55.  
  56.  
  57. for (int i= 0; i < 10; i++){
  58. for(int j = 0; j < 10; j++){
  59. if (maze[i][j] == wall)
  60. cout << "+";
  61. if (maze[i][j] == space)
  62. cout << " ";
  63. if (maze[i][j] == ext)
  64. cout << "E";
  65. if (maze[i][j] == X)
  66. cout << "X";
  67. }
  68.  
  69. cout << endl;
  70.  
  71.  
  72. }
  73. }
  74.  
  75. bool robotMove(int &Rnum, int &Cnum){
  76.  
  77.  
  78. while (maze[Rnum][Cnum] != ext) {
  79. unsigned seed;
  80. seed = time(0);
  81. srand(seed);
  82. int random = rand() % 4;
  83.  
  84. if ((random = 0) && (maze[Rnum -1][Cnum] = space))
  85. {//up
  86. maze[Rnum -1][Cnum] = X;
  87. [Rnum][Cnum] = space;
  88. }
  89. if ((random = 1) && (maze[Rnum +1][Cnum] = space))
  90. {// down
  91. maze[Rnum + 1][Cnum] = X;
  92. maze[Rnum][Cnum] = space;
  93. }
  94. if ((random = 2) && (maze[Rnum][Cnum - 1] = space))
  95. {// left
  96. maze[Rnum][Cnum -1] = X;
  97. maze[Rnum][Cnum] = space;
  98. }
  99. if ((random = 3) && (maze[Rnum][Cnum + 1] = space))
  100. {// right
  101. maze[Rnum][Cnum + 1] = X;
  102. maze[Rnum][Cnum] = space;
  103. }
  104. ++ numbermoves;
  105. }
  106.  
  107.  
  108.  
  109.  
  110. }
Add Comment
Please, Sign In to add comment