diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-26 12:54:15 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-26 12:54:15 +0300 |
| commit | 492ed6b629d5f1e22fd53f2f44b911d0a45d01f7 (patch) | |
| tree | ef0e0e0faa84e64d4560d400bff89b76bee75474 /map.c | |
| parent | 056ffbf79ff554d7338b0234a2e69b66eb799da1 (diff) | |
| download | astar-492ed6b629d5f1e22fd53f2f44b911d0a45d01f7.tar.xz | |
Add cost_array into neighbours_8dir()
Diffstat (limited to 'map.c')
| -rw-r--r-- | map.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -24,7 +24,7 @@ Map empty_map(size_t width, size_t height) { } /* Honestly, what a shitty fucking way to implement this */ -unsigned int neighbours_4dir(Position neighbour_array[], Position pos, size_t width, size_t height, \ +unsigned int neighbours_4dir(Position neighbour_array[4], Position pos, size_t width, size_t height, \ char visited[height][width]) { size_t cur = 0; if (pos.x > 0 && !visited[pos.y][pos.x - 1]) { @@ -51,48 +51,56 @@ unsigned int neighbours_4dir(Position neighbour_array[], Position pos, size_t wi return cur; } -unsigned int neighbours_8dir(Position neighbour_array[], Position pos, size_t width, size_t height, \ +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]) { size_t cur = 0; if (pos.x > 0 && !visited[pos.y][pos.x - 1]) { neighbour_array[cur].x = pos.x - 1; neighbour_array[cur].y = pos.y; + if (cost_array != NULL) cost_array[cur] = 10; cur += 1; } if (pos.x + 1 < width && !visited[pos.y][pos.x + 1]) { neighbour_array[cur].x = pos.x + 1; neighbour_array[cur].y = pos.y; + if (cost_array != NULL) cost_array[cur] = 10; cur += 1; } if (pos.y > 0 && !visited[pos.y - 1][pos.x]) { neighbour_array[cur].x = pos.x; neighbour_array[cur].y = pos.y - 1; + if (cost_array != NULL) cost_array[cur] = 10; cur += 1; } if (pos.y + 1 < height && !visited[pos.y + 1][pos.x]) { neighbour_array[cur].x = pos.x; neighbour_array[cur].y = pos.y + 1; + if (cost_array != NULL) cost_array[cur] = 10; cur += 1; } if (pos.x > 0 && pos.y > 0 && !visited[pos.y - 1][pos.x - 1]) { neighbour_array[cur].x = pos.x - 1; neighbour_array[cur].y = pos.y - 1; + if (cost_array != NULL) cost_array[cur] = 14; cur += 1; } if (pos.x + 1 < width && pos.y > 0 && !visited[pos.y - 1][pos.x + 1]) { neighbour_array[cur].x = pos.x + 1; neighbour_array[cur].y = pos.y - 1; + if (cost_array != NULL) cost_array[cur] = 14; cur += 1; } if (pos.x + 1 < width && pos.y + 1 < height && !visited[pos.y + 1][pos.x + 1]) { neighbour_array[cur].x = pos.x + 1; neighbour_array[cur].y = pos.y + 1; + if (cost_array != NULL) cost_array[cur] = 14; cur += 1; } if (pos.x > 0 && pos.y + 1 < height && !visited[pos.y + 1][pos.x - 1]) { neighbour_array[cur].x = pos.x - 1; neighbour_array[cur].y = pos.y + 1; + if (cost_array != NULL) cost_array[cur] = 14; cur += 1; } |
