aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c9
-rw-r--r--map.c7
-rw-r--r--path.c10
-rw-r--r--path.h1
-rw-r--r--structs.h1
5 files changed, 22 insertions, 6 deletions
diff --git a/main.c b/main.c
index cac6a85..b77d554 100644
--- a/main.c
+++ b/main.c
@@ -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;
diff --git a/map.c b/map.c
index 035623a..544164e 100644
--- a/map.c
+++ b/map.c
@@ -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 */
diff --git a/path.c b/path.c
index fd92908..a8410fc 100644
--- a/path.c
+++ b/path.c
@@ -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;
diff --git a/path.h b/path.h
index 002690d..10f79e9 100644
--- a/path.h
+++ b/path.h
@@ -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);
diff --git a/structs.h b/structs.h
index 801b1a6..9b8b13e 100644
--- a/structs.h
+++ b/structs.h
@@ -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.