//create the pathways as well as start and end cells for the maze void Maze::setupMaze() { bool done = false; while (!done) { createMaze(); done = checkMaze(); } }
bool get_input() { bool isCorrectInput = true; char c; int x_dim = 0; int y_dim = 0; while ((c = getchar()) != EOF) { if (isspace(c) || (c >= '0' && c <= '3') || c == '\n') { switch (c) { case ' ': break; case '0': case '1': case '2': case '3': if (x_dim > 31) { isCorrectInput = false; } else { maze[y_dim][x_dim++] = c; } break; case '\n': if (x_dim != 0 && x_dim >= 2) { x_dim = 0; y_dim++; } else if (y_dim > 41 || x_dim == 1) { isCorrectInput = false; } break; } } else { isCorrectInput = false; break; } } if (isCorrectInput && y_dim >= 2) { x_dim = 0; for (int i = 0; i < MAX_X_DIM; i++) { if (isdigit(maze[0][i])) x_dim++; } isCorrectInput = checkMaze(x_dim, y_dim); } if (isCorrectInput) { actual_x_dim = x_dim; actual_y_dim = y_dim; } return isCorrectInput; }
int main(int argc, char **argv) { if (argc < 2) { printf("You need a valid input maze file.\n"); return -1; } printf("Creating maze with file %s\n", argv[1]); maze_t * maze = createMaze(argv[1]); printf("\nUnsolved maze:\n"); printMaze(maze); if(solveMazeManhattanDFS(maze, maze->startColumn, maze->startRow)) { printf("\nSolved maze:\n"); printMaze(maze); if(checkMaze(maze)) { printf("Solution to maze is valid\n"); } else { printf("Incorrect solution to maze\n"); } } else { printf("\nMaze is unsolvable\n"); } printf("\nDestroying maze\n"); destroyMaze(maze); return 0; }