diff --git a/sk1a/main.c b/sk1a/main.c index 38c5fb1..95139d5 100644 --- a/sk1a/main.c +++ b/sk1a/main.c @@ -15,11 +15,11 @@ void print_solution(char* matrix,int sz){ int main(){ char tmaze[SZ+1][SZ+1]={ - "*x ", - " x ", - " x ", - " x ", - " ", + "*x ", + " xx ", + " x ", + " x ", + " ", }; char maze[SZ*SZ]; memset(maze,' ',SZ*SZ); diff --git a/sk1a/main.o b/sk1a/main.o index c7ee5e6..f4a04da 100644 Binary files a/sk1a/main.o and b/sk1a/main.o differ diff --git a/sk1a/maze.c b/sk1a/maze.c index d078bb5..98825c2 100644 --- a/sk1a/maze.c +++ b/sk1a/maze.c @@ -5,21 +5,79 @@ int solve_maze(char* maze,int size) { int i = 0; + int p, l, h, d = 0; while(i != size*size-1){ - if (maze[i + 1] == ' ' && i != size - 1) { + if (maze[i + 1] == ' ' && i != size - 1 && l != 1) { maze[i + 1] = '*'; i++; - } else if (maze[i + size] == ' ' && i != size - 1) { + p = 0; + l = 0; + h = 0; + d = 0; + } else if (maze[i + size] == ' ' && i != size - 1 && h != 1) { maze[i + size] = '*'; i = i + size; - } else if (maze[i - 1] == ' ' && i != 0) { + p = 0; + l = 0; + h = 0; + d = 0; + } else if (maze[i - 1] == ' ' && i != 0 && p != 1) { maze[i - 1] = '*'; i--; - } else if (maze[i - size] == ' ' && i > size) { + p = 0; + l = 0; + h = 0; + d = 0; + } else if (maze[i - size] == ' ' && i > size && d != 1) { maze[i - size] = '*'; i = i - size; + p = 0; + l = 0; + h = 0; + d = 0; + } + else{ + while(1){ + + if (maze[i + 1] == ' ' && i != size - 1 && l != 1) { + i++; + break; + } + if (maze[i + size] == ' ' && i != size - 1 && h != 1) { + i = i + size; + break; + } + if (maze[i - 1] == ' ' && i != 0 && p != 1) { + i--; + break; + } + if (maze[i - size] == ' ' && i > size && d != 1) { + i = i - size; + break; + } + p = 0; + l = 0; + h = 0; + d = 0; + if (maze[i + 1] == '*' && i != size - 1) { + maze[i] = ' '; + i++; + p = 1; + } else if (maze[i + size] == '*' && i != size - 1) { + maze[i] = ' '; + i = i + size; + d = 1; + } else if (maze[i - 1] == '*' && i != 0) { + maze[i] = ' '; + i--; + l = 1; + } else if (maze[i - size] == '*' && i > size) { + maze[i] = ' '; + i = i - size; + h = 1; + } + } } } - return 1; } diff --git a/sk1a/maze.o b/sk1a/maze.o index c8ded7d..d13f7c7 100644 Binary files a/sk1a/maze.o and b/sk1a/maze.o differ diff --git a/sk1a/program b/sk1a/program index 1c484b5..f892103 100644 Binary files a/sk1a/program and b/sk1a/program differ