aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-04-23 14:42:55 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-04-23 14:42:55 +0300
commitb4b83c53db8b79a2141ef43ce9d3567f482462ee (patch)
tree14e93576b7dc2e846cc60981e27bc71e620fed5f
parent53ed90ab4f3b493f1c3abd4aff4fa45f3f8a0909 (diff)
downloadastar-b4b83c53db8b79a2141ef43ce9d3567f482462ee.tar.xz
Allow switching amount of directions with a keybind
-rw-r--r--main.c10
-rw-r--r--map.c10
2 files changed, 20 insertions, 0 deletions
diff --git a/main.c b/main.c
index db1d7a8..98093dc 100644
--- a/main.c
+++ b/main.c
@@ -160,6 +160,7 @@ int main(int argc, char **argv) {
draw_map(map, cell_costs, width, height, start_pos, end_pos, NULL, path, visited, NULL);
int c = getch();
+ /* TODO: keybinding to change dir amount */
/*
* Keybindings:
* [k] \
@@ -185,6 +186,7 @@ int main(int argc, char **argv) {
* [A] - Force animate
*
* [d] - Switch algorithms (A* or Dijsktra's)
+ * [4] - Switch amount of directions (4 or 8)
*
* [f] - Toggle wraparound
*
@@ -280,6 +282,14 @@ int main(int argc, char **argv) {
/* TODO: print time */
break;
+ case '4':
+ if (dirs == 4) { set_message("8 directions"); dirs = 8; }
+ else { set_message("4 directions"); dirs = 4; };
+
+ path_free(path, height);
+ path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim);
+ break;
+
case 'f':
wraparound_enabled = !wraparound_enabled;
if (wraparound_enabled)
diff --git a/map.c b/map.c
index 85cc073..11f9eb6 100644
--- a/map.c
+++ b/map.c
@@ -659,6 +659,7 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
* [a] - Toggle pathfinding
*
* [d] - Switch algorithms (A* or Dijsktra's)
+ * [4] - Switch amount of directions (4 or 8)
*
* [r] - Reverse path
*
@@ -719,6 +720,15 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
case 'd':
if (path_func == astar_path) { set_message("Dijkstra's"); path_func = &dijkstra_path; }
else { set_message("A*"); path_func = &astar_path; };
+
+ path_free(path, *height);
+ if (should_pathfind) path = path_func(dirs, *map, NULL, *width, *height, *start, *goal, visited, 0);
+ break;
+
+ case '4':
+ if (dirs == 4) { set_message("8 directions"); dirs = 8; }
+ else { set_message("4 directions"); dirs = 4; };
+
path_free(path, *height);
if (should_pathfind) path = path_func(dirs, *map, NULL, *width, *height, *start, *goal, visited, 0);
break;