usaa21/sk1a/maze.c

49 lines
726 B
C
Raw Normal View History

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-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-21 23:31:30 +00:00
if(journey >= 0 && journey <= (size*size) && maze[journey]==' ' && maze[journey]!='*'){
2022-01-21 23:24:40 +00:00
maze[journey] = '*';
2022-01-21 21:13:58 +00:00
2022-01-21 20:53:46 +00:00
//Pohyb dole
2022-01-21 23:24:40 +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-21 23:24:40 +00:00
if(paths(maze, journey+1, size)){
return 1;
2022-01-09 00:12:46 +00:00
}
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
/* if(paths(maze, journey-1, size))
return 1;
*/
maze[journey] = ' ';
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
}
2022-01-21 23:24:40 +00:00