1. #include <iostream>
  2. #include <fstream>
  3. #include <windows.h>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. struct direction
  9. {
  10. int xD;
  11. int yD;
  12. };
  13.  
  14. direction Up, Do, Le, Ri;
  15.  
  16. Up.xD = 0;
  17. Up.yD = -1;
  18.  
  19. Do.xD = 0;
  20. Do.yD = 1;
  21.  
  22. Le.xD = -1;
  23. Le.yD = 0;
  24.  
  25. Ri.xD = 1;
  26. Ri.yD = 0;
  27.  
  28. char maze[100][100];
  29. char solvedMaze[100][100];
  30.  
  31. void clearMaze(char maze[][100]);
  32.  
  33. void readMaze(char maze[][100], int &rows, int &columns, string filename)
  34. // Reads the maze from the text file with the name passed to the function
  35.  
  36. {
  37. ifstream inputMaze;
  38. inputMaze.open(filename.c_str());
  39. inputMaze >> rows >> columns;
  40. string templine;
  41. int temprow, tempcolumn;
  42. temprow = 0;
  43. getline(inputMaze, templine);
  44. // Clears the end line character from the maze
  45. clearMaze(maze);
  46. while(!inputMaze.eof())
  47. {
  48. getline(inputMaze, templine);
  49. for(tempcolumn=0; tempcolumn < columns; tempcolumn++)
  50. {
  51. maze[temprow][tempcolumn] = templine[tempcolumn];
  52. }
  53. temprow++;
  54. }
  55.  
  56. inputMaze.close();
  57. }
  58.  
  59. void clearMaze(char maze[][100])
  60. // Sets every character in the maze to a wall
  61.  
  62. // Extra walls outside of the maze will not effect the solving of the maze
  63.  
  64. // Since we are given the dimensions of the maze, it will not affect the output
  65. // of the maze, either.
  66.  
  67. {
  68. int i, j;
  69. for(i=0; i<100; i++)
  70. {
  71. for(j=0; j<100; j++)
  72. {
  73. maze[i][j] = '*';
  74. }
  75. }
  76. }
  77.  
  78. void displayMaze(char maze[][100], int rows, int columns)
  79. // Displays the maze
  80. {
  81. for(int i = 0; i < rows; i++)
  82. {
  83. for(int j = 0; j < columns; j++)
  84. {
  85. cout << maze[i][j];
  86. }
  87. cout << endl;
  88. }
  89. }
  90.  
  91. void makeMove(char maze[][100], direction direct, int &X, int &Y)
  92. {
  93. // I will finish this later >.>
  94.  
  95. }
  96.  
  97. void solveMaze(char maze[][100], int rows, int columns)
  98. {
  99. int X, Y;
  100. X = 1;
  101. Y = 1;
  102. direction currentDirection = Ri;
  103. // We start at (1,1), or maze[1][1]
  104. //
  105. // We wish to get to (columns - 1, rows - 1), or maze[rows-1][columns-1]
  106. while(X != (columns - 1) && Y != (rows - 1))
  107. {
  108. makeMove(maze, currentDirection, X, Y);
  109. }
  110.  
  111. }
  112.  
  113.  
  114.  
  115.  
  116. int main()
  117. {
  118.  
  119. int rows, columns;
  120. string firstline, filename;
  121. filename = "maze1.txt";
  122. readMaze(maze, rows, columns, filename);
  123. displayMaze(maze, rows, columns);
  124. char cc;
  125. cin >> cc;
  126. return 0;
  127. }
  128.  
  129.