diff options
| -rw-r--r-- | main.c | 9 | ||||
| -rw-r--r-- | map.c | 7 | ||||
| -rw-r--r-- | path.c | 10 | ||||
| -rw-r--r-- | path.h | 1 | ||||
| -rw-r--r-- | structs.h | 1 |
5 files changed, 22 insertions, 6 deletions
@@ -16,8 +16,6 @@ /* So, TODO for now: - Allow maps to have costs - - Write out the amount of visited squares (to see how algorithms differ in - efficiency) - check ppq_insert() order - more info in anim() - save pathfinding to a series of BMPs @@ -44,6 +42,7 @@ void initialize_colors(void) { init_pair(PATH_COLOR, COLOR_YELLOW, COLOR_RED); init_pair(FRONTIER_COLOR, COLOR_BLUE, COLOR_BLUE); init_pair(CURSOR_COLOR, -1, COLOR_RED); + init_pair(WALL_TEXT_COLOR, COLOR_BLACK, COLOR_WHITE); } void init_ncurses(void) { @@ -180,8 +179,8 @@ int main(int argc, char **argv) { case 'a': anim = !anim; break; case 'd': - if (path_func == astar_path) path_func = &dijkstra_path; - else path_func = &astar_path; + if (path_func == astar_path) { set_message("Dijkstra"); path_func = &dijkstra_path; } + else { set_message("A*"); path_func = &astar_path; }; path_free(path, height); path = path_func(dirs, map, width, height, start_pos, end_pos, visited, anim); break; @@ -192,7 +191,7 @@ int main(int argc, char **argv) { case 'i': if(is_maze) { switch (c) { - case 'y': if (mwidth > 2) mwidth -= 1; break; + case 'y': if (mwidth > 5) mwidth -= 1; break; case 'o': mwidth += 1; break; case 'u': mheight += 1; break; case 'i': if (mheight > 2) mheight -= 1; break; @@ -373,7 +373,12 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa cur = path[cur.y][cur.x].parent; } attroff(COLOR_PAIR(PATH_COLOR)); - /* FIXME: print this as part of bottom wall? set_message("Path cost: %zu", length); */ + attron(COLOR_PAIR(WALL_TEXT_COLOR)); + mvprintw(map_offset_y - 1, map_offset_x, "Path cost: %zu", length); + if (visited != NULL) { + mvprintw(height + map_offset_y, map_offset_x, "Visited %zu cells", visited_count(visited, width, height)); + } + attroff(COLOR_PAIR(WALL_TEXT_COLOR)); } /* Draw the start */ @@ -348,6 +348,16 @@ void visited_free(char **visited, size_t height) { return; } +size_t visited_count(char **visited, size_t width, size_t height) { + size_t count = 0; + for (size_t row = 0; row < height; row++) { + for (size_t col = 0; col < width; col++) { + if (visited[row][col]) count++; + } + } + return count; +} + size_t **cost_so_far_new(size_t width, size_t height) { size_t **cost_so_far = malloc(sizeof(size_t*) * height); if (cost_so_far == NULL) return NULL; @@ -20,6 +20,7 @@ size_t path_length(Path path, Position start, Position goal); char **visited_new(size_t width, size_t height); void visited_clear(char **visited, size_t width, size_t height); void visited_free(char **visited, size_t height); +size_t visited_count(char **visited, size_t width, size_t height); /* Helper funcs for the cost_so_far array */ size_t **cost_so_far_new(size_t width, size_t height); @@ -25,6 +25,7 @@ enum Colors_e { PATH_COLOR = 6, FRONTIER_COLOR = 7, CURSOR_COLOR = 8, + WALL_TEXT_COLOR = 9, }; /* A map is a 2D array of MapTiles. |
