2022-01-09 00:12:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "maze.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2022-01-21 23:24:40 +00:00
|
|
|
int paths(char* maze, int journey, int size){
|
2022-01-22 01:27:27 +00:00
|
|
|
printf("journy je:%d\n",journey);
|
2022-01-21 20:53:46 +00:00
|
|
|
|
2022-01-21 23:24:40 +00:00
|
|
|
if(journey == size*size-1){
|
|
|
|
maze[journey]= '*';
|
|
|
|
return 1;
|
|
|
|
}
|
2022-01-21 22:22:19 +00:00
|
|
|
|
2022-01-22 01:04:03 +00:00
|
|
|
if(journey >= 0 && journey <= (size*size) && maze[journey]==' '){
|
2022-01-22 00:57:10 +00:00
|
|
|
|
|
|
|
maze[journey] = '*';
|
2022-01-21 21:13:58 +00:00
|
|
|
|
2022-01-21 20:53:46 +00:00
|
|
|
//Pohyb dole
|
2022-01-22 00:57:10 +00:00
|
|
|
if(journey < (size * size) - (size)){
|
2022-01-22 01:27:27 +00:00
|
|
|
puts("dole");
|
2022-01-22 00:57:10 +00:00
|
|
|
if(paths(maze, journey+size, size)){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2022-01-21 22:22:19 +00:00
|
|
|
|
2022-01-21 23:24:40 +00:00
|
|
|
|
2022-01-21 20:53:46 +00:00
|
|
|
//Pohyb vpravo
|
2022-01-22 00:57:10 +00:00
|
|
|
if((journey+1)%size!=0) {
|
2022-01-22 01:27:27 +00:00
|
|
|
puts("vpravo");
|
2022-01-22 00:57:10 +00:00
|
|
|
if (paths(maze, journey + 1, size)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2022-01-21 21:13:58 +00:00
|
|
|
|
2022-01-21 23:24:40 +00:00
|
|
|
//Pohyb hore
|
|
|
|
if(paths(maze, journey-size, size)){
|
|
|
|
return 1;
|
|
|
|
}
|
2022-01-09 00:12:46 +00:00
|
|
|
|
2022-01-21 23:24:40 +00:00
|
|
|
//Pohyb vlavo
|
2022-01-22 00:57:10 +00:00
|
|
|
if((journey%size)!=0){
|
2022-01-22 01:27:27 +00:00
|
|
|
puts("vlavo");
|
2022-01-22 00:38:19 +00:00
|
|
|
if(paths(maze, journey-1, size))
|
|
|
|
return 1;
|
|
|
|
}
|
2022-01-22 00:57:10 +00:00
|
|
|
|
2022-01-21 23:24:40 +00:00
|
|
|
maze[journey] = ' ';
|
2022-01-22 00:59:30 +00:00
|
|
|
return 0;
|
2022-01-21 20:53:46 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 23:24:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2022-01-09 00:12:46 +00:00
|
|
|
|
2022-01-21 23:24:40 +00:00
|
|
|
int solve_maze(char* maze, int size){
|
|
|
|
return paths(maze, 0, size);
|
2022-01-09 00:12:46 +00:00
|
|
|
}
|