From 492ed6b629d5f1e22fd53f2f44b911d0a45d01f7 Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Thu, 26 Mar 2026 12:54:15 +0300 Subject: Add cost_array into neighbours_8dir() --- map.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'map.c') diff --git a/map.c b/map.c index 2bf3ab0..9f1d206 100644 --- a/map.c +++ b/map.c @@ -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; } -- cgit v1.2.3