49 lines
726 B
C
49 lines
726 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "maze.h"
|
|
#include <assert.h>
|
|
#include <math.h>
|
|
|
|
int paths(char* maze, int journey, int size){
|
|
|
|
if(journey == size*size-1){
|
|
maze[journey]= '*';
|
|
return 1;
|
|
}
|
|
|
|
if(journey >= 0 && journey <= (size*size) && maze[journey]==' ' && maze[journey]!='*'){
|
|
maze[journey] = '*';
|
|
|
|
//Pohyb dole
|
|
if(paths(maze, journey+size, size)){
|
|
return 1;
|
|
}
|
|
|
|
|
|
//Pohyb vpravo
|
|
if(paths(maze, journey+1, size)){
|
|
return 1;
|
|
}
|
|
|
|
|
|
//Pohyb hore
|
|
if(paths(maze, journey-size, size)){
|
|
return 1;
|
|
}
|
|
|
|
//Pohyb vlavo
|
|
/* if(paths(maze, journey-1, size))
|
|
return 1;
|
|
*/
|
|
|
|
maze[journey] = ' ';
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int solve_maze(char* maze, int size){
|
|
return paths(maze, 0, size);
|
|
}
|
|
|