aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-03-28 19:33:49 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-03-28 19:33:49 +0300
commit1f0dd604952e39d030367b2bbf45b69f8c63cc5b (patch)
treea1389804dbb9301a6691704e4c5c0eb829df4a4b /map.c
parent5b623c0a31d6732dd03ba8db80004e5468bc08c3 (diff)
downloadastar-1f0dd604952e39d030367b2bbf45b69f8c63cc5b.tar.xz
Allow resizing the map + some other stuff
Diffstat (limited to 'map.c')
-rw-r--r--map.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/map.c b/map.c
index d527cec..f26d4b1 100644
--- a/map.c
+++ b/map.c
@@ -27,7 +27,7 @@ Map empty_map(size_t width, size_t height) {
/* When we allow maps to have costs, these two neighbours functions will have to use the instead of COST_* defines */
/* TODO: maybe merge them, add `dirs` parameter, like we do in path.c? */
unsigned int neighbours_4dir(Position neighbour_array[4], size_t cost_array[4], Position pos, size_t width, size_t height, \
- char visited[height][width]) {
+ char **visited) {
size_t cur = 0;
if (pos.x > 0 && !visited[pos.y][pos.x - 1]) {
neighbour_array[cur].x = pos.x - 1;
@@ -58,7 +58,7 @@ unsigned int neighbours_4dir(Position neighbour_array[4], size_t cost_array[4],
}
unsigned int neighbours_8dir(Position neighbour_array[8], size_t cost_array[8], Position pos, size_t width, size_t height, \
- char visited[height][width]) {
+ char **visited) {
size_t cur = 0;
if (pos.x > 0 && !visited[pos.y][pos.x - 1]) {
neighbour_array[cur].x = pos.x - 1;
@@ -133,8 +133,8 @@ Map rbt_maze_map(size_t width, size_t height, unsigned int seed) {
Position beginning_cell = {width - 1, height - 1};
- char visited[height][width]; /* 1 if visited, 0 if not */
- memset(visited, 0, sizeof(char) * width * height);
+ char **visited = visited_new(width, height);
+ visited_clear(visited, width, height);
PositionStack ps = ps_new();
if (ps_push(&ps, beginning_cell) == -1) error("Is the STACK_SIZE zero?");
@@ -157,6 +157,7 @@ Map rbt_maze_map(size_t width, size_t height, unsigned int seed) {
}
} while (ps_peek(ps).x != beginning_cell.x || ps_peek(ps).y != beginning_cell.y) ;
+ visited_free(visited, height);
return map;
}
@@ -208,7 +209,7 @@ Map file_plaintext_map(char *filename, size_t *width, size_t *height, Position *
/* TODO: so many fucking arguments lmao. Break it down into several functions? */
/* TODO: draw the start and goal with no background, allowing us to see the frontier/path/whatever's underneath. I think attr_get() will be useful */
-void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y, Position start, Position goal, Position *cursor, Path path, char visited[height][width], PositionPQ *frontier) {
+void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y, Position start, Position goal, Position *cursor, Path path, char **visited, PositionPQ *frontier) {
/* I think it flickers less when we do that */
wnoutrefresh(stdscr);
@@ -223,6 +224,8 @@ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y,
mvaddch(i + offset_y, DRAW_MAP_OFFSET_X - 1 + offset_x - 2, ' ');
mvaddch(i + offset_y, DRAW_MAP_OFFSET_X + width * 2 + offset_x + 2, ' ');
mvaddch(i + offset_y, DRAW_MAP_OFFSET_X + width * 2 + 1 + offset_x + 2, ' ');
+ mvaddch(i + offset_y, DRAW_MAP_OFFSET_X + width * 2 + 2 + offset_x + 2, ' ');
+ mvaddch(i + offset_y, DRAW_MAP_OFFSET_X + width * 2 + 3 + offset_x + 2, ' ');
}
/* Draw the borders */