diff --git a/sk1a/main.o b/sk1a/main.o index 18d8162..6366a96 100644 Binary files a/sk1a/main.o and b/sk1a/main.o differ diff --git a/sk1a/maze.c b/sk1a/maze.c index 38467cf..eac876d 100644 --- a/sk1a/maze.c +++ b/sk1a/maze.c @@ -4,7 +4,7 @@ #include int issafe(char* maze, int x, int y, int size) { - if ((x >= 0 && x < size) && (y >= 0 && y < size) && maze[x * size + y] == ' '){ + if ((x >= 0 && x < size) && (y >= 0 && y < size) && (maze[x * size + y] == ' ')){ return 1; } return 0; @@ -37,41 +37,5 @@ int backtracking(char* maze, int x, int y, int size){ } int solve_maze(char* maze, int size) { - if (maze[0] == '*'){ - assert(maze[0] == '*'); - maze[0] = ' '; - } - int x,y = 0; - while(x * size + y <= size*size - 1 ){ - printf("%d\n%d", x * size + y, y); - //issafe(maze, x, y, size); - if (maze[x * size + y + 1] == ' ' /*&& y != 5*/){ - assert(maze[x * size + y + 1] == ' '); - maze[x * size + y + 1] = '*'; - y++; - - } - if (maze[(x + 1) * size + y] == ' ' /*&& x != 5*/){ - assert(maze[(x + 1) * size + y] == ' '); - maze[(x + 1) * size + y] = '*'; - x++; - - } - if (maze[x * size + y - 1] == ' ' && y != 0){ - assert(maze[x * size + y - 1] == ' '); - maze[x * size + y - 1] = '*'; - y--; - - } - if (maze[(x - 1) * size + y] == ' ' /*&& x != 0*/){ - assert(maze[(x - 1) * size + y] == ' '); - maze[(x - 1) * size + y] = '*'; - x--; - - } - else{ - backtracking(maze,x , y, size); - } - } -return 1; + return backtracking(maze, 0, 0, size); } diff --git a/sk1a/maze.o b/sk1a/maze.o index 1f464df..2f07d75 100644 Binary files a/sk1a/maze.o and b/sk1a/maze.o differ diff --git a/sk1a/program b/sk1a/program index b681ad3..bba069e 100644 Binary files a/sk1a/program and b/sk1a/program differ diff --git a/sk1a/readme.md b/sk1a/readme.md new file mode 100644 index 0000000..021a40a --- /dev/null +++ b/sk1a/readme.md @@ -0,0 +1,41 @@ +#include +#include +#include "maze.h" +#include + +int issafe(char* maze, int x, int y, int size) { +if ((x >= 0 && x < size) && (y >= 0 && y < size) && (maze[x * size + y] == ' ')){ +return 1; +} +return 0; +} + +int backtracking(char* maze, int x, int y, int size){ +if(x == size - 1 && y == size - 1 && maze[x * size + y] == ' '){ +maze[x * size + y] = '*'; +return 1; +} + + if(issafe(maze, x, y, size) == 1) { + maze[x * size + y] = '*'; + + if (backtracking(maze, x, y + 1, size) == 1) { + return 1; + } + if (backtracking(maze, x + 1, y, size) == 1) { + return 1; + } + if (backtracking(maze, x - 1, y, size) == 1) { + return 1; + } + if (backtracking(maze, x, y - 1, size) == 1) { + return 1; + } + maze[x * size + y] = ' '; + } + return 0; +} + +int solve_maze(char* maze, int size) { +return backtracking(maze, 0, 0, size); +} \ No newline at end of file