diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 51 |
1 files changed, 39 insertions, 12 deletions
@@ -14,14 +14,14 @@ #include "path.h" /* So, TODO for now: - - Keybinds to increase map size + - Generate an image?? - Allow maps to have costs - Implement greedy-best-first algorithm (4 and 8 dir) - Implement Dijkstra algorithm (4 and 8 dir) - Implement the A* algorithm (4 and 8 dir) - MORE MAPS FOR THE MAP PEOPLE - Implement controls (to change maps, move start/goal, etc.) - - Clean up unused `#include`s + - Clean up unused `#include`s - mouse controls to edit map, drag start and end around */ void sigint_handler(int sig) { @@ -37,7 +37,7 @@ void initialize_colors(void) { init_pair(EMPTY_COLOR, COLOR_BLACK, -1); init_pair(VISITED_COLOR, COLOR_GREEN, COLOR_GREEN); init_pair(GOAL_COLOR, -1, COLOR_RED); - init_pair(WALL_COLOR, COLOR_WHITE, COLOR_WHITE); + init_pair(WALL_COLOR, COLOR_WHITE, COLOR_WHITE); init_pair(START_COLOR, -1, COLOR_RED); init_pair(PATH_COLOR, COLOR_RED, COLOR_RED); init_pair(FRONTIER_COLOR, COLOR_BLUE, COLOR_BLUE); @@ -65,7 +65,7 @@ int main(int argc, char **argv) { int dirs = 8; srand(time(NULL)); - + /* Handle args. * Currently supported: * -a to animate the pathfinding (get input after each step) @@ -74,6 +74,7 @@ int main(int argc, char **argv) { * -4 for four directions * -8 for eight directions */ /* TODO: Argument to choose the algorithm */ + /* TODO: Argument to set seed */ int opt; while ((opt = getopt(argc, argv, ":am:f:48")) != -1) { switch (opt) { @@ -81,7 +82,7 @@ int main(int argc, char **argv) { case 'm': if (sscanf(optarg, "%zux%zu", &mwidth, &mheight) != 2) error("Wrong maze size string in argument\n"); is_maze = 1; - map = rbt_maze_map(mwidth, mheight, (unsigned int) time(NULL)); + map = rbt_maze_map(mwidth, mheight, rand()); start_pos.x = 0; start_pos.y = 0; height = mheight * 2 - 1; @@ -122,7 +123,7 @@ int main(int argc, char **argv) { draw_map(map, width, height, offset_x, offset_y, start_pos, end_pos, NULL, NULL, NULL, NULL); //print_map_out(map, width, height); - char visited[height][width]; + char **visited = visited_new(width, height); Path path = NULL; path = breadth_first_search_path(dirs, map, width, height, start_pos, end_pos, visited, anim); @@ -130,13 +131,39 @@ int main(int argc, char **argv) { draw_map(map, width, height, offset_x, offset_y, start_pos, end_pos, NULL, path, visited, NULL); char c = getch(); switch (c) { - case 'h': offset_x -= 2; break; - case 'l': offset_x += 2; break; - case 'j': offset_y += 1; break; - case 'k': offset_y -= 1; break; + /* FIXME: scroll the view not the content or whatever */ + case 'h': offset_x += 2; break; + case 'l': offset_x -= 2; break; + case 'j': offset_y -= 1; break; + case 'k': offset_y += 1; break; case 'a': anim = !anim; break; - case 'n': - if (is_maze) { + case 'y': + case 'o': + case 'u': + case 'i': + if(is_maze) { + switch (c) { + case 'y': mwidth -= 1; break; + case 'o': mwidth += 1; break; + case 'u': mheight += 1; break; + case 'i': mheight -= 1; break; + } + map_free(map, height); + visited_free(visited, height); + path_free(path, height); + + height = mheight * 2 - 1; + width = mwidth * 2 - 1; + end_pos.x = width - 1; + end_pos.y = height - 1; + + map = rbt_maze_map(mwidth, mheight, rand()); + visited = visited_new(width, height); + path = breadth_first_search_path(dirs, map, width, height, start_pos, end_pos, visited, anim); + } + break; + case 'n': + if (is_maze) { map_free(map, height); map = rbt_maze_map(mwidth, mheight, rand()); path_free(path, height); |
