aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--map.c71
1 files changed, 69 insertions, 2 deletions
diff --git a/map.c b/map.c
index 3859bd9..8868e11 100644
--- a/map.c
+++ b/map.c
@@ -196,8 +196,75 @@ unsigned int neighbours_8dir(Position neighbour_array[8], size_t cost_array[8],
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();
+ size_t cur = 0;
+
+ Position poses[8];
+ 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};
+
+ size_t x, y;
+ /* Top-left */
+ if (pos.x == 0) x = width - 1;
+ else x = pos.x - 1;
+ if (pos.y == 0) y = height - 1;
+ else y = pos.y - 1;
+ poses[4] = (Position) { .x = x, .y = y };
+
+ /* Top-right */
+ if (pos.x == width - 1) x = 0;
+ else x = pos.x + 1;
+ if (pos.y == 0) y = height - 1;
+ else y = pos.y - 1;
+ poses[5] = (Position) { .x = x, .y = y };
+
+ /* Bottom-left */
+ if (pos.x == 0) x = width - 1;
+ else x = pos.x - 1;
+ if (pos.y == height - 1) y = 0;
+ else y = pos.y + 1;
+ poses[6] = (Position) { .x = x, .y = y };
+
+ /* Bottom-right */
+ if (pos.x == width - 1) x = 0;
+ else x = pos.x + 1;
+ if (pos.y == height - 1) y = 0;
+ else y = pos.y + 1;
+ poses[7] = (Position) { .x = x, .y = y };
+
+ for (int i = 0; i < 8; 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) {
+ size_t dir_cost = COST_ORTHOGONAL;
+ if (i > 3) dir_cost = COST_DIAGONAL;
+ if (costs != NULL) cost_array[cur] = costs[p.y][p.x] * dir_cost;
+ else cost_array[cur] = dir_cost;
+ }
+ cur += 1;
+ }
+ }
+
+ return cur;
}
Map rbt_maze_map(size_t width, size_t height, unsigned int seed) {