usaa21/sk1a/maze.c
2022-01-03 18:28:22 +01:00

84 lines
2.3 KiB
C

#include <stdio.h>
#include <string.h>
#include "maze.h"
#include <assert.h>
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 && l != 1) {
maze[i + 1] = '*';
i++;
p = 0;
l = 0;
h = 0;
d = 0;
} else if (maze[i + size] == ' ' && i != size - 1 && h != 1) {
maze[i + size] = '*';
i = i + size;
p = 0;
l = 0;
h = 0;
d = 0;
} else if (maze[i - 1] == ' ' && i != 0 && p != 1) {
maze[i - 1] = '*';
i--;
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;
}