aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-05-03 13:12:25 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-05-03 13:12:25 +0300
commit6fc30f8bb3bd345a30a36936e4008c3703aa01f0 (patch)
treeceffbb702a4449bb79cae17c08d2c163d5defb7d
parent702b04c89752fb16f165f5d26c99df5895c0fab4 (diff)
downloadastar-6fc30f8bb3bd345a30a36936e4008c3703aa01f0.tar.xz
Print algo name when printing time
-rw-r--r--config.h3
-rw-r--r--main.c7
-rw-r--r--map.c7
-rw-r--r--path.c1
-rw-r--r--path.h2
5 files changed, 14 insertions, 6 deletions
diff --git a/config.h b/config.h
index 0c2679a..de53416 100644
--- a/config.h
+++ b/config.h
@@ -76,6 +76,9 @@
/* --- End of keybindings --- */
+#define ASTAR_STRING "A*"
+#define DIJKSTRA_STRING "Dijkstra's"
+
#define MESSAGE_MAX_SIZE 256
#define FILENAME_BUF_SIZE 128
diff --git a/main.c b/main.c
index 3120c3b..a83dadd 100644
--- a/main.c
+++ b/main.c
@@ -269,8 +269,9 @@ int main(int argc, char **argv) {
break;
case KEYBINDING_ALGO:
- if (path_func == astar_path) { set_message("Dijkstra's"); path_func = &dijkstra_path; }
- else { set_message("A*"); path_func = &astar_path; };
+ if (path_func == astar_path) { path_func_string = DIJKSTRA_STRING; path_func = &dijkstra_path; }
+ else { path_func_string = ASTAR_STRING; path_func = &astar_path; };
+ set_message("%s", path_func_string);
path_free(path, height);
path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim);
/* TODO: print time */
@@ -383,7 +384,7 @@ int main(int argc, char **argv) {
}
break;
case KEYBINDING_PATH_TIME:
- set_message("%f seconds", path_time); print_message(height);
+ set_message("%f seconds (%s)", path_time, path_func_string); print_message(height);
break;
case KEYBINDING_LOAD_COSTS: /* Load a cost file */
diff --git a/map.c b/map.c
index 28a87ea..a5e528c 100644
--- a/map.c
+++ b/map.c
@@ -727,8 +727,9 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
break;
case KEYBINDING_ALGO:
- if (path_func == astar_path) { set_message("Dijkstra's"); path_func = &dijkstra_path; }
- else { set_message("A*"); path_func = &astar_path; };
+ if (path_func == astar_path) { path_func_string = DIJKSTRA_STRING; path_func = &dijkstra_path; }
+ else { path_func_string = ASTAR_STRING; path_func = &astar_path; };
+ set_message("%s", path_func_string);
path_free(path, *height);
if (should_pathfind) path = path_func(dirs, *map, NULL, *width, *height, *start, *goal, visited, 0);
@@ -769,7 +770,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
break;
case KEYBINDING_PATH_TIME:
- set_message("%f seconds", path_time); print_message(*height);
+ set_message("%f seconds (%s)", path_time, path_func_string); print_message(*height);
break;
case KEYBINDING_SAVE_MAP:
diff --git a/path.c b/path.c
index 9a2fe1f..f1e46b0 100644
--- a/path.c
+++ b/path.c
@@ -13,6 +13,7 @@
#include "config.h"
Path (*path_func)(int, Map, size_t **, size_t, size_t, Position, Position, char **, char) = &astar_path;
+char *path_func_string = ASTAR_STRING;
double path_time = 0;
char wraparound_enabled = 0;
diff --git a/path.h b/path.h
index 459bca6..28c9b72 100644
--- a/path.h
+++ b/path.h
@@ -6,6 +6,8 @@
/* The currently chosen path func */
extern Path (*path_func)(int, Map, size_t **, size_t, size_t, Position, Position, char **, char);
+/* The string that represents the current algo */
+extern char *path_func_string;
/* Time it took to calculate a path */
extern double path_time;