From c940ec9916781f818b21fe4d24b155e735eaea69 Mon Sep 17 00:00:00 2001 From: Peter Petrek Date: Fri, 14 Jan 2022 02:26:39 +0100 Subject: [PATCH] print --- sk1a/maze.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/sk1a/maze.c b/sk1a/maze.c index 14aaf7d..f0d1f8b 100644 --- a/sk1a/maze.c +++ b/sk1a/maze.c @@ -20,12 +20,16 @@ int solve_maze(char* maze, int size) { return 0; } + printf("\n"); char maze2d[size][size]; for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { + printf("%c ", maze[size * y + x]); maze2d[y][x] = maze[size * y + x] == 'x' ? 'x' : 0; } + printf("\n"); } + printf("\nend %d\n\n", size); int posY = 0, posX = 0; @@ -93,30 +97,30 @@ int solve_maze(char* maze, int size) { maze2d[0][0] = '*'; //cleanup data bits - for (int i = 0; i < size; i++) { - for (int j = 0; j < size; j++) { - if (maze2d[i][j] == CHECKED_BIT || maze2d[i][j] == 0) { - maze2d[i][j] = ' '; - } else if (maze2d[i][j] != 'x') { - maze2d[i][j] = '*'; + for (int y = 0; y < size; y++) { + for (int x = 0; x < size; x++) { + if (maze2d[y][x] == CHECKED_BIT || maze2d[y][x] == 0) { + maze2d[y][x] = ' '; + } else if (maze2d[y][x] != 'x') { + maze2d[y][x] = '*'; } } } //cleanup redundant routes - for (int i = size - 2; i >= 0; i--) { - for (int j = size - 2; j >= 0; j--) { - if (maze2d[i][j] == '*' && maze2d[i + 1][j] == '*' && maze2d[i + 1][j + 1] == '*' && maze2d[i][j + 1] == '*') { - maze2d[i + 1][j + 1] = ' '; - maze2d[i][j + 1] = ' '; + for (int y = size - 2; y >= 0; y--) { + for (int x = size - 2; x >= 0; x--) { + if (maze2d[y][x] == '*' && maze2d[y + 1][x] == '*' && maze2d[y + 1][x + 1] == '*' && maze2d[y][x + 1] == '*') { + maze2d[y + 1][x + 1] = ' '; + maze2d[y][x + 1] = ' '; } } } //serialize - for (int i = 0; i < size; i++) { - for (int j = 0; j < size; j++) { - maze[i * size + j] = maze2d[i][j]; + for (int y = 0; y < size; y++) { + for (int x = 0; x < size; x++) { + maze[y * size + x] = maze2d[y][x]; } }