Crosswind

maze

Jun 12th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.29 KB | None | 0 0
  1. int maze(unsigned char labyrinth[100][100], uint8_t size_x, uint8_t size_y, uint8_t start_x, uint8_t start_y) {
  2.     // for moving up in the maze
  3.     if (start_x > 0) {
  4.         if (labyrinth[start_x - 1][start_y] == MAZE_FINISH) {
  5.             return 0;
  6.         } else {
  7.             if (labyrinth[start_x - 1][start_y] == MAZE_WALKWAY) {
  8.                 labyrinth[start_x - 1][start_y] = MAZE_STEP;
  9.                 if (maze(labyrinth, size_x, size_y, start_x - 1, start_y) == 0) {
  10.                     return 0;
  11.                 } else {
  12.                     labyrinth[start_x - 1][start_y] = MAZE_WRONG;
  13.                 }
  14.             }
  15.         }
  16.     }
  17.     // for moving down in the maze
  18.     if (start_x < size_x) {
  19.         if (labyrinth[start_x + 1][start_y] == MAZE_FINISH) {
  20.             return 0;
  21.         } else {
  22.             if (labyrinth[start_x + 1][start_y] == MAZE_WALKWAY) {
  23.                 labyrinth[start_x + 1][start_y] = MAZE_STEP;
  24.                 if (maze(labyrinth, size_x, size_y, start_x + 1, start_y) == 0) {
  25.                     return 0;
  26.                 } else {
  27.                     labyrinth[start_x + 1][start_y] = MAZE_WRONG;
  28.                 }
  29.             }
  30.         }
  31.     }
  32.     // for moving left in the maze
  33.     if (start_y > 0) {
  34.         if (labyrinth[start_x][start_y - 1] == MAZE_FINISH) {
  35.             return 0;
  36.         } else {
  37.             if (labyrinth[start_x][start_y - 1] == MAZE_WALKWAY) {
  38.                 labyrinth[start_x][start_y + 1] = MAZE_STEP;
  39.                 if (maze(labyrinth, size_x, size_y, start_x, start_y - 1) == 0) {
  40.                     return 0;
  41.                 } else {
  42.                     labyrinth[start_x][start_y - 1] = MAZE_WRONG;
  43.                 }
  44.             }
  45.         }
  46.     }
  47.     // for moving right in the maze
  48.     if (start_y < size_y) {
  49.         if (labyrinth[start_x][start_y + 1] == MAZE_FINISH) {
  50.             return 0;
  51.         } else {
  52.             if (labyrinth[start_x][start_y + 1] == MAZE_WALKWAY) {
  53.                 labyrinth[start_x][start_y + 1] = MAZE_STEP;
  54.                 if (maze(labyrinth, size_x, size_y, start_x, start_y + 1) == 0) {
  55.                     return 0;
  56.                 } else {
  57.                     labyrinth[start_x][start_y + 1] = MAZE_WRONG;
  58.                 }
  59.             }
  60.         }
  61.     }
  62.     return 1;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment