This commit is contained in:
Damián Korpesio 2022-01-04 20:39:32 +01:00
parent fb9c572281
commit eb8de40367
5 changed files with 14 additions and 13 deletions

View File

@ -15,11 +15,12 @@ void print_solution(char* matrix,int sz){
int main(){ int main(){
char tmaze[SZ+1][SZ+1]={ char tmaze[SZ+1][SZ+1]={
"*x ", "*x ",
" xx ", " xx ",
" x ", " x ",
" x ", " x ",
" ", " ",
" ",
}; };
char maze[SZ*SZ]; char maze[SZ*SZ];
memset(maze,' ',SZ*SZ); memset(maze,' ',SZ*SZ);

Binary file not shown.

View File

@ -7,28 +7,28 @@ int solve_maze(char* maze,int size) {
int i = 0; int i = 0;
int p, l, h, d = 0; int p, l, h, d = 0;
while(i != size*size-1){ while(i != size*size-1){
if (maze[i + 1] == ' ' && i != size - 1 && l != 1) { if (maze[i + 1] == ' ' && i % size - 1 && l != 1) {
maze[i + 1] = '*'; maze[i + 1] = '*';
i++; i++;
p = 0; p = 0;
l = 0; l = 0;
h = 0; h = 0;
d = 0; d = 0;
} else if (maze[i + size] == ' ' && i != size - 1 && h != 1) { } else if (maze[i + size] == ' ' /*&& i < size*size - size*/ && h != 1) {
maze[i + size] = '*'; maze[i + size] = '*';
i = i + size; i = i + size;
p = 0; p = 0;
l = 0; l = 0;
h = 0; h = 0;
d = 0; d = 0;
} else if (maze[i - 1] == ' ' && i != 0 && p != 1) { } else if (maze[i - 1] == ' ' /*&& i % size*/ && p != 1) {
maze[i - 1] = '*'; maze[i - 1] = '*';
i--; i--;
p = 0; p = 0;
l = 0; l = 0;
h = 0; h = 0;
d = 0; d = 0;
} else if (maze[i - size] == ' ' && i > size && d != 1) { } else if (maze[i - size] == ' ' /*&& i >= size*/ && d != 1) {
maze[i - size] = '*'; maze[i - size] = '*';
i = i - size; i = i - size;
p = 0; p = 0;
@ -40,19 +40,19 @@ int solve_maze(char* maze,int size) {
while(1){ while(1){
if (maze[i + 1] == ' ' && i != size - 1 && l != 1) { if (maze[i + 1] == ' ' && i != size - 1 && l != 1) {
i++; //i++;
break; break;
} }
if (maze[i + size] == ' ' && i != size - 1 && h != 1) { if (maze[i + size] == ' ' && i != size - 1 && h != 1) {
i = i + size; //i = i + size;
break; break;
} }
if (maze[i - 1] == ' ' && i != 0 && p != 1) { if (maze[i - 1] == ' ' && i != 0 && p != 1) {
i--; //i--;
break; break;
} }
if (maze[i - size] == ' ' && i > size && d != 1) { if (maze[i - size] == ' ' && i > size && d != 1) {
i = i - size; //i = i - size;
break; break;
} }
p = 0; p = 0;

Binary file not shown.

Binary file not shown.