aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--map.c48
-rw-r--r--map.h6
2 files changed, 54 insertions, 0 deletions
diff --git a/map.c b/map.c
index d0e48a6..3859bd9 100644
--- a/map.c
+++ b/map.c
@@ -72,6 +72,48 @@ unsigned int neighbours_4dir(Position neighbour_array[4], size_t cost_array[4],
return cur;
}
+unsigned int neighbours_4dir_wraparound(Position neighbour_array[4], size_t cost_array[4], Position pos, size_t width, size_t height, \
+ char **visited, size_t **costs) {
+ size_t cur = 0;
+
+ Position poses[4];
+ if (pos.x == 0) /* Left */
+ poses[0] = (Position) { .x = width - 1, .y = pos.y };
+ else
+ poses[0] = (Position) { .x = pos.x - 1, .y = pos.y };
+
+ if (pos.y == 0) /* Up */
+ poses[1] = (Position) { .x = pos.x, .y = height - 1 };
+ else
+ poses[1] = (Position) { .x = pos.x, .y = pos.y - 1};
+
+ if (pos.x == width - 1) /* Right */
+ poses[2] = (Position) { .x = 0, .y = pos.y };
+ else
+ poses[2] = (Position) { .x = pos.x + 1, .y = pos.y };
+
+ if (pos.y == height - 1) /* Down */
+ poses[3] = (Position) { .x = pos.x, .y = 0 };
+ else
+ poses[3] = (Position) { .x = pos.x, .y = pos.y + 1};
+
+ for (int i = 0; i < 4; i++) {
+ Position p = poses[i];
+
+ if (!visited[p.y][p.x]) {
+ neighbour_array[cur].x = p.x;
+ neighbour_array[cur].y = p.y;
+ if (cost_array != NULL) {
+ if (costs != NULL) cost_array[cur] = costs[p.y][p.x] * COST_ORTHOGONAL;
+ else cost_array[cur] = COST_ORTHOGONAL;
+ }
+ cur += 1;
+ }
+ }
+
+ return cur;
+}
+
unsigned int neighbours_8dir(Position neighbour_array[8], size_t cost_array[8], Position pos, size_t width, size_t height, \
char **visited, size_t **costs) {
size_t cur = 0;
@@ -152,6 +194,12 @@ unsigned int neighbours_8dir(Position neighbour_array[8], size_t cost_array[8],
return cur;
}
+unsigned int neighbours_8dir_wraparound(Position neighbour_array[8], size_t cost_array[8], Position pos, size_t width, size_t height, \
+ char **visited, size_t **costs) {
+ (void) neighbour_array, (void) cost_array, (void) pos, (void) width, (void) height, (void) visited, (void) costs;
+ todo();
+}
+
Map rbt_maze_map(size_t width, size_t height, unsigned int seed) {
size_t map_width = width * 2 - 1,
map_height = height * 2 - 1;
diff --git a/map.h b/map.h
index 7faa597..16c731f 100644
--- a/map.h
+++ b/map.h
@@ -20,11 +20,17 @@ Map empty_map(size_t width, size_t height);
/* Stores all the existing 4dir neighbours of pos in neighbour_array and returns their amount */
unsigned int neighbours_4dir(Position neighbour_array[4], size_t cost_array[4], Position pos, size_t width, size_t height, \
char **visited, size_t **costs);
+/* Same as above, but walls wrap around. IMPORTANT: the heuristic is tuned to no wraparound, so only dijkstras will work correctly */
+unsigned int neighbours_4dir_wraparound(Position neighbour_array[4], size_t cost_array[4], Position pos, size_t width, size_t height, \
+ char **visited, size_t **costs);
/* Stores all the existing 8dir neighbours of pos in neighbour_array and returns their amount.
* Additionaly stores costs into cost_array if it's not NULL.
* The cost of goint orthogonally is 10, diagonaly is 14 (sqrt(2) * 10) */
unsigned int neighbours_8dir(Position neighbour_array[8], size_t cost_array[8], Position pos, size_t width, size_t height, \
char **visited, size_t **costs);
+/* Same as above, but walls wrap around. IMPORTANT: the heuristic is tuned to no wraparound, so only dijkstras will work correctly */
+unsigned int neighbours_8dir_wraparound(Position neighbour_array[8], size_t cost_array[8], Position pos, size_t width, size_t height, \
+ char **visited, size_t **costs);
/* https://en.wikipedia.org/wiki/Maze_generation_algorithm#Randomized_depth-first_search
* WARNING: width and height are not the width and height of the returned map!