diff --git a/sk1a/maze.c b/sk1a/maze.c index 31c6668..14aaf7d 100644 --- a/sk1a/maze.c +++ b/sk1a/maze.c @@ -32,9 +32,9 @@ int solve_maze(char* maze, int size) { while (1) { enum direction next_step; - if (posX + 1 != size && maze2d[posY][posX + 1] != 'x' && !(maze2d[posY][posX + 1] & CHECKED_BIT)) { + if (posX + 1 < size && maze2d[posY][posX + 1] != 'x' && !(maze2d[posY][posX + 1] & CHECKED_BIT)) { next_step = EAST; - } else if (posY + 1 != size && maze2d[posY + 1][posX] != 'x' && !(maze2d[posY + 1][posX] & CHECKED_BIT)) { + } else if (posY + 1 < size && maze2d[posY + 1][posX] != 'x' && !(maze2d[posY + 1][posX] & CHECKED_BIT)) { next_step = SOUTH; } else if (posX - 1 >= 0 && maze2d[posY][posX - 1] != 'x' && !(maze2d[posY][posX - 1] & CHECKED_BIT)) { next_step = WEST; @@ -104,14 +104,14 @@ int solve_maze(char* maze, int size) { } //cleanup redundant routes - /*for (int i = size - 2; i >= 0; i--) { + 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] = ' '; } } - }*/ + } //serialize for (int i = 0; i < size; i++) {