diff options
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; } |
