This commit is contained in:
Peter Petrek 2022-01-14 02:26:39 +01:00
parent 45badc437a
commit c940ec9916

View File

@ -20,12 +20,16 @@ int solve_maze(char* maze, int size) {
return 0; return 0;
} }
printf("\n");
char maze2d[size][size]; char maze2d[size][size];
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
printf("%c ", maze[size * y + x]);
maze2d[y][x] = maze[size * y + x] == 'x' ? 'x' : 0; maze2d[y][x] = maze[size * y + x] == 'x' ? 'x' : 0;
} }
printf("\n");
} }
printf("\nend %d\n\n", size);
int posY = 0, posX = 0; int posY = 0, posX = 0;
@ -93,30 +97,30 @@ int solve_maze(char* maze, int size) {
maze2d[0][0] = '*'; maze2d[0][0] = '*';
//cleanup data bits //cleanup data bits
for (int i = 0; i < size; i++) { for (int y = 0; y < size; y++) {
for (int j = 0; j < size; j++) { for (int x = 0; x < size; x++) {
if (maze2d[i][j] == CHECKED_BIT || maze2d[i][j] == 0) { if (maze2d[y][x] == CHECKED_BIT || maze2d[y][x] == 0) {
maze2d[i][j] = ' '; maze2d[y][x] = ' ';
} else if (maze2d[i][j] != 'x') { } else if (maze2d[y][x] != 'x') {
maze2d[i][j] = '*'; maze2d[y][x] = '*';
} }
} }
} }
//cleanup redundant routes //cleanup redundant routes
for (int i = size - 2; i >= 0; i--) { for (int y = size - 2; y >= 0; y--) {
for (int j = size - 2; j >= 0; j--) { for (int x = size - 2; x >= 0; x--) {
if (maze2d[i][j] == '*' && maze2d[i + 1][j] == '*' && maze2d[i + 1][j + 1] == '*' && maze2d[i][j + 1] == '*') { if (maze2d[y][x] == '*' && maze2d[y + 1][x] == '*' && maze2d[y + 1][x + 1] == '*' && maze2d[y][x + 1] == '*') {
maze2d[i + 1][j + 1] = ' '; maze2d[y + 1][x + 1] = ' ';
maze2d[i][j + 1] = ' '; maze2d[y][x + 1] = ' ';
} }
} }
} }
//serialize //serialize
for (int i = 0; i < size; i++) { for (int y = 0; y < size; y++) {
for (int j = 0; j < size; j++) { for (int x = 0; x < size; x++) {
maze[i * size + j] = maze2d[i][j]; maze[y * size + x] = maze2d[y][x];
} }
} }