aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'map.c')
-rw-r--r--map.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/map.c b/map.c
index 9443bcf..262d2ec 100644
--- a/map.c
+++ b/map.c
@@ -57,50 +57,50 @@ unsigned int neighbours_8dir(Position neighbour_array[8], size_t cost_array[8],
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;
+ if (cost_array != NULL) cost_array[cur] = COST_ORTHOGONAL;
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;
+ if (cost_array != NULL) cost_array[cur] = COST_ORTHOGONAL;
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;
+ if (cost_array != NULL) cost_array[cur] = COST_ORTHOGONAL;
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;
+ if (cost_array != NULL) cost_array[cur] = COST_ORTHOGONAL;
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;
+ if (cost_array != NULL) cost_array[cur] = COST_DIAGONAL;
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;
+ if (cost_array != NULL) cost_array[cur] = COST_DIAGONAL;
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;
+ if (cost_array != NULL) cost_array[cur] = COST_DIAGONAL;
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;
+ if (cost_array != NULL) cost_array[cur] = COST_DIAGONAL;
cur += 1;
}
@@ -209,8 +209,9 @@ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y,
for (ssize_t i = -1; i <= (ssize_t)(width*2 + 4); i++) { /* Horizontal */
mvaddch(DRAW_MAP_OFFSET_Y - 1 + offset_y - 1, i + offset_x, ' ');
mvaddch(DRAW_MAP_OFFSET_Y + height + offset_y + 1, i + offset_x, ' ');
+ mvaddch(DRAW_MAP_OFFSET_Y + height + offset_y + 2, i + offset_x, ' ');
}
- for (size_t i = 0; i <= height + 2; i++) { /* Horizontal */
+ for (size_t i = 0; i <= height + 2; i++) { /* Vertical */
mvaddch(i + offset_y, DRAW_MAP_OFFSET_X - 2 + offset_x - 2, ' ');
mvaddch(i + offset_y, DRAW_MAP_OFFSET_X - 1 + offset_x - 2, ' ');
mvaddch(i + offset_y, DRAW_MAP_OFFSET_X + width * 2 + offset_x + 2, ' ');
@@ -286,13 +287,21 @@ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y,
/* Draw path */
if (path != NULL) {
+ size_t length = 0;
attron(COLOR_PAIR(PATH_COLOR));
Position cur = goal;
while (cur.x != start.x || cur.y != start.y) {
mvaddch(cur.y + DRAW_MAP_OFFSET_Y + offset_y, cur.x*2 + DRAW_MAP_OFFSET_X + offset_x, ' ');
mvaddch(cur.y + DRAW_MAP_OFFSET_Y + offset_y, cur.x*2 + DRAW_MAP_OFFSET_X + 1 + offset_x, ' ');
+ if (cur.x - path[cur.y][cur.x].parent.x == 0 || cur.y - path[cur.y][cur.x].parent.y == 0) {
+ length += COST_ORTHOGONAL;
+ } else {
+ length += COST_DIAGONAL;
+ }
cur = path[cur.y][cur.x].parent;
}
+ attroff(COLOR_PAIR(PATH_COLOR));
+ mvprintw(height + offset_y + DRAW_MAP_OFFSET_Y + 1, offset_x, "Path cost: %zu", length);
}
/* Draw the start */