diff --git a/sk1a/maze.c b/sk1a/maze.c index c9a4c2f..d675f92 100644 --- a/sk1a/maze.c +++ b/sk1a/maze.c @@ -4,61 +4,55 @@ #include #include -int solve_maze(char* maze, int size){ - for(int i = 0; i < size * size; i++){ - if(maze[i] == ' '){ - maze[i] = '*'; - continue; - }else{ - i = i+size-2; + + +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; + printf("acpos: %d\n", actualPos); continue; } + + //Pohyb vpravo + if(maze[actualPos+1]==' '){ + puts("vpravo"); + maze[actualPos]='*'; + actualPos++; + continue; + } + + //Pohyb hore + /* if(maze[actualPos-size]==' ' && actualPos-size != 0){ + maze[actualPos-size]='*'; + actualPos-=size; + continue; + }*/ + +/* + //Pohyb vlavo + if(maze[actualPos-1]==' '){ + maze[actualPos]='*'; + actualPos--; + continue; + } +*/ + + + } + + + + return 1; } - -/*int solve_maze(char* maze,int size){ - - char smaze[size+1][size+1]; - char* wmaze = smaze; - int k = 0; - memset(smaze, 0, size); - for (int i = 0; i < size; i++) { - for (int j = 0; j < size; j++) { - smaze[i][j] = maze[k]; - k++; - } - - } - - for (int i = 0; i < size; i++) { - for (int j = 0; j < size; j++) { - printf("%c ",smaze[i][j]); - - } - printf("\n"); - } - - - int r = findWay(0,0,size); - - return r; -} - - - - -int findWay(int i, int j, int size){ - - if(wmaze[i][j] == ' '){ - - wmaze[i][j] = '*'; - if(findWay(i, j+1, size) == 1) return 1; - if(findWay(i+1, j+1, size) == 1) return 1; - - wmaze[i][j] = ' '; - } - return 0; -} - -*/