diff --git a/sk1a/maze.c b/sk1a/maze.c index ed2a7e1..458e002 100644 --- a/sk1a/maze.c +++ b/sk1a/maze.c @@ -4,63 +4,45 @@ #include #include +int paths(char* maze, int journey, int size){ - -int solve_maze(char* maze,int size){ - - //int end = size*size; - int actualPos = 0; - maze[actualPos]='*'; - - while(actualPos != size*size-1){ - //printf("acpos: %d\n", actualPos); - - - - //Pohyb dole - if(actualPos < (size*size-size) && maze[actualPos+size]==' '){ - //printf("dole\n"); - maze[actualPos+size]='*'; - actualPos+=size; - continue; - } - - //Pohyb hore - if(actualPos-size > size && maze[actualPos-size]==' '){ - //printf("hore\n"); - maze[actualPos-size]='*'; - actualPos-=size; - continue; - }else if(actualPos-size > size && maze[actualPos-size]=='*'){ - maze[actualPos]=' '; - actualPos-=size; - } - - //Pohyb vpravo - if(maze[actualPos+1]==' '){ - //puts("vpravo"); - maze[actualPos+1]='*'; - actualPos++; - continue; - } - - - - //Pohyb vlavo - if(maze[actualPos-1]==' '){ - //printf("vlavo\n"); - maze[actualPos]='*'; - actualPos--; - continue; - } - - - - + if(journey == size*size-1){ + maze[journey]= '*'; + return 1; } + if(journey >= 0 && journey < (size*size) && 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; +*/ - return 1; + maze[journey] = ' '; + } + + return 0; } + +int solve_maze(char* maze, int size){ + return paths(maze, 0, size); +} +