diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-23 13:48:37 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-23 13:48:37 +0300 |
| commit | 483c635bda691556084042710f3f5c5f0d81c047 (patch) | |
| tree | 98a2b2a0fb9b41d6a0c1711b4309a9e7cf48fb84 /map.c | |
| parent | 092fbe195d22dfecb768c98f91b6ab733f1bb72f (diff) | |
| download | astar-483c635bda691556084042710f3f5c5f0d81c047.tar.xz | |
Implement 4dir wraparound
Diffstat (limited to 'map.c')
| -rw-r--r-- | map.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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; |
