hm
This commit is contained in:
parent
9c8babdb69
commit
c5a4386d1e
14
sk1a/maze.c
14
sk1a/maze.c
@ -5,6 +5,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
int paths(char* maze, int journey, int size){
|
int paths(char* maze, int journey, int size){
|
||||||
|
//printf("journy je:%d\n",journey);
|
||||||
|
|
||||||
if(journey == size*size-1){
|
if(journey == size*size-1){
|
||||||
maze[journey]= '*';
|
maze[journey]= '*';
|
||||||
@ -12,19 +13,23 @@ int paths(char* maze, int journey, int size){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(journey >= 0 && journey < (size*size) && maze[journey]==' '){
|
if(journey >= 0 && journey < (size*size) && maze[journey]==' '){
|
||||||
|
|
||||||
maze[journey] = '*';
|
maze[journey] = '*';
|
||||||
|
|
||||||
//Pohyb dole
|
//Pohyb dole
|
||||||
|
if(journey < (size * size) - (size)){
|
||||||
if(paths(maze, journey+size, size)){
|
if(paths(maze, journey+size, size)){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Pohyb vpravo
|
//Pohyb vpravo
|
||||||
if(paths(maze, journey+1, size)){
|
if((journey+1)%size!=0) {
|
||||||
|
if (paths(maze, journey + 1, size)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Pohyb hore
|
//Pohyb hore
|
||||||
if(paths(maze, journey-size, size)){
|
if(paths(maze, journey-size, size)){
|
||||||
@ -32,11 +37,11 @@ int paths(char* maze, int journey, int size){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Pohyb vlavo
|
//Pohyb vlavo
|
||||||
if(size%journey!=0){
|
if((journey%size)!=0){
|
||||||
if(paths(maze, journey-1, size))
|
if(paths(maze, journey-1, size))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
maze[journey] = ' ';
|
maze[journey] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,4 +51,3 @@ int paths(char* maze, int journey, int size){
|
|||||||
int solve_maze(char* maze, int size){
|
int solve_maze(char* maze, int size){
|
||||||
return paths(maze, 0, size);
|
return paths(maze, 0, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user