You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
946 B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <stdbool.h>
  6. #include "labyrinth.h"
  7. int printlabyrinth(lab laby, int hoehe, int breite){
  8. for(int i = 0; i < hoehe; i++){
  9. for(int j = 0; j < breite; j++){
  10. printf("%c ", laby[i][j]);
  11. }
  12. printf("\n");
  13. }
  14. printf("\n");
  15. return 0;
  16. }
  17. void wegsuchen(lab laby, bool* done, int y, int x, int ziely, int zielx){
  18. laby[y][x] = 'X';
  19. if(x == zielx && y == ziely){
  20. *done = true;
  21. }
  22. else{
  23. if (!*done && y + 1 <= ziely && laby[y+1][x] == '0'){
  24. wegsuchen(laby, done, y + 1, x, ziely, zielx);
  25. }
  26. if (!*done && x + 1 <= zielx && laby[y][x+1] == '0'){
  27. wegsuchen(laby, done, y, x + 1, ziely, zielx);
  28. }
  29. if (!*done && y - 1 >= 0 && laby[y-1][x] == '0'){ // oben
  30. wegsuchen(laby, done, y - 1, x, ziely, zielx);
  31. }
  32. }
  33. }