Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. int main(){
  2.  
  3. int i,j, end;
  4. FILE*fp;
  5. fp=fopen("totalmaze.txt","r+");
  6.  
  7. for(i = 0;i<120;i++){
  8. for(j=0;j<22;j++){
  9. fscanf(fp,"%d",&maze[i][j]);
  10. }
  11. }
  12.  
  13. int xstart,ystart,xend,yend,mazenumber;
  14.  
  15. printf("This program will solve array maze 1 through 6.n");
  16. printf("Which maze would you like to solve? Enter a number 1 through 6.n");
  17.  
  18. scanf("%d",&mazenumber);
  19. printf("Please enter the starting position.n");
  20. printf("row? (maze 1 = row 0, maze 2 = row 0, maze 3 = row 0, maze 4 = row 0, maze 5 = row 0, maze 6 = row 2 )n");
  21.  
  22. scanf("%d",&xstart);
  23. printf("column? (maze 1 = column 9, maze 2 = column 9, maze 3 = column 2, maze 4 = column 2, maze 5 = column 2, maze 6 = column 0 )n");
  24.  
  25. scanf("%d",&ystart);
  26. printf("Please enter the ending position.n");
  27. printf("row? (maze 1 = row 19, maze 2 = row 15, maze 3 = row 7, maze 4 = row 7, maze 5 = row 19, maze 6 = row 19)n");
  28.  
  29. scanf("%d",&xend);
  30. printf("column? (maze 1 = column 12, maze 2 = column 21, maze 3 = column 21, maze 4 = column 21, maze 5 = column 16, maze 6 = column 16)n");
  31.  
  32. scanf("%d",&yend);
  33. printf("nn");
  34.  
  35. int x =0;
  36. if(mazenumber==1){
  37. i =0;
  38. end = 19;
  39. }
  40.  
  41. if(mazenumber==2){
  42. i = 20;
  43. end = 39;
  44. }
  45.  
  46. if(mazenumber==3){
  47. i = 40;
  48. end = 59;
  49. }
  50.  
  51. if(mazenumber==4){
  52. i = 60;
  53. end = 79;
  54. }
  55.  
  56. if(mazenumber==5){
  57. i = 80;
  58. end = 99;
  59. }
  60.  
  61. if(mazenumber==6){
  62. i = 100;
  63. end = 119;
  64. }
  65.  
  66. for(i; i <= end; i++)
  67. {
  68. for(j=0; j < 22; j++)
  69. {
  70. solution[x][j] = maze[i][j];
  71. }
  72. x++;
  73. }
  74.  
  75. int a,b;
  76. for(a = 0; a < 20; a++)
  77. {
  78. for(b = 0; b < 22; b++)
  79. {
  80. printf("%d ", solution[a][b]);
  81. }
  82. printf("n");
  83. }
  84.  
  85. if (solvemaze(xstart, ystart, xend, yend))
  86. printsolution();
  87. else
  88. printf("No solution was found. Mario has died.n");
  89.  
  90. return 0;
  91. }
  92.  
  93. int solvemaze(int xstart, int ystart, int xend, int yend){
  94.  
  95. int xpos = xstart;
  96. int ypos = ystart;
  97. int prevX;
  98. int prevY;
  99. int tempX = xpos;
  100. int tempY = ypos;
  101.  
  102. solution[xpos][ypos] = 1;
  103.  
  104. while((xpos != xend) && (ypos != yend))
  105. {
  106. //down
  107. if((maze[tempX++][ypos]!=5) && (tempX != r))
  108. {
  109. solution[tempX][ypos] = 1;
  110. prevX = xpos;
  111. prevY = ypos;
  112. xpos++;
  113. printsolution();
  114. printf("nn");
  115. printf("nn");
  116. tempX = xpos;
  117. tempY = ypos;
  118. continue;
  119. }
  120. //right
  121. else if((maze[xpos][tempY++]!=5)&& (tempY != c))
  122. {
  123. solution[xpos][tempY]=1;
  124. prevX = xpos;
  125. prevY = ypos;
  126. ypos++;
  127. printsolution();
  128. printf("nn");
  129. printf("nn");
  130. tempX = xpos;
  131. tempY = ypos;
  132. continue;
  133. }
  134. //left
  135. else if((maze[xpos][tempY--]!=5) && (tempY != -1))
  136. {
  137. solution[xpos][tempY]=1;
  138. prevX = xpos;
  139. prevY = ypos;
  140. ypos--;
  141. printsolution();
  142. printf("nn");
  143. printf("nn");
  144. tempX = xpos;
  145. tempY = ypos;
  146. continue;
  147. }
  148. //up
  149. else if((maze[tempX--][ypos]!=5) && (tempX != -1))
  150. {
  151. solution[tempX][ypos]=1;
  152. prevX = xpos;
  153. prevY = ypos;
  154. xpos--;
  155. printsolution();
  156. tempX = xpos;
  157. tempY = ypos;
  158. printf("nn");
  159. printf("nn");
  160. continue;
  161. }
  162. else
  163. {
  164. solution[xpos][ypos] = 5;
  165. xpos = prevX;
  166. ypos = prevY;
  167. }
  168. }
  169.  
  170. if((xpos == xend) && (ypos == yend))
  171. {
  172. printf("Mario had been rescued!n");
  173. return 1;
  174. }
  175. else
  176. return 0;
  177.  
  178. }
  179.  
  180. 5555555550555555555555
  181.  
  182. 5555555550555555555555
  183.  
  184. 5555555550555555555555
  185.  
  186. 5555555550555555555555
  187.  
  188. 5555555550555555555555
  189.  
  190. 5555555550000000055555
  191.  
  192. 5555555555555555055555
  193.  
  194. 5555555555555555055555
  195.  
  196. 5555555555555555055555
  197.  
  198. 5555555555555555055555
  199.  
  200. 5555550000000000055555
  201.  
  202. 5555550555555555555555
  203.  
  204. 5555550555555555555555
  205.  
  206. 5555550555555555555555
  207.  
  208. 5555550555555555555555
  209.  
  210. 5555550555555555555555
  211.  
  212. 5555550555555555555555
  213.  
  214. 5555550000000555555555
  215.  
  216. 5555555555550555555555
  217.  
  218. 5555555555550555555555
  219.  
  220. 5555555551555555555555
  221.  
  222. 5555555551555555555555
  223.  
  224. 5555555551555555555555
  225.  
  226. 5555555551555555555555
  227.  
  228. 5555555551555555555555
  229.  
  230. 5555555551111000055555
  231.  
  232. 5555555555555555055555
  233.  
  234. 5555555555555555055555
  235.  
  236. 5555555555555555055555
  237.  
  238. 5555555555555555055555
  239.  
  240. 5555550000000000055555
  241.  
  242. 5555550555555555555555
  243.  
  244. 5555550555555555555555
  245.  
  246. 5555550555555555555555
  247.  
  248. 5555550555555555555555
  249.  
  250. 5555550555555555555555
  251.  
  252. 5555550555555555555555
  253.  
  254. 5555550000000555555555
  255.  
  256. 5555555555550555555555
  257.  
  258. 5555555555550555555555
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement