#ifndef MAP_H_ #define MAP_H_ #include #include "structs.h" #include "path.h" #include "priority_queue.h" extern int map_offset_x; extern int map_offset_y; /* Returns an empty map of given size */ Map empty_map(size_t width, size_t height); /* Stores all the existing 4dir neighbours of pos in neighbour_array and returns their amount */ unsigned int neighbours_4dir(Position neighbour_array[4], size_t cost_array[4], Position pos, size_t width, size_t height, \ char **visited); /* Stores all the existing 8dir neighbours of pos in neighbour_array and returns their amount. * Additionaly stores costs into cost_array if it's not NULL. * The cost of goint orthogonally is 10, diagonaly is 14 (sqrt(2) * 10) */ unsigned int neighbours_8dir(Position neighbour_array[8], size_t cost_array[8], Position pos, size_t width, size_t height, \ char **visited); /* https://en.wikipedia.org/wiki/Maze_generation_algorithm#Randomized_depth-first_search * WARNING: width and height are not the width and height of the returned map! * The actual size for a given dimention is (dimension * 2 - 1) */ Map rbt_maze_map(size_t width, size_t height, unsigned int seed); /* Reads the map from a file, saves size in `width` and `height` * * FILE FORMAT IS AS FOLLOWS: * {WIDTH}x{HEIGHT} * {EMPTY_CHAR}{WALL_CHAR}{START_CHAR}{END_CHAR} * {MAP, one line at a time} * * EXAMPLE: * 10x4 * .#@x * .......x.. * ....###... * ....#.#... * ..@....... */ Map file_plaintext_map(char *filename, size_t *width, size_t *height, Position *start_pos, Position *end_pos); /* Draw the map. Bet you didn't expect that. * path could be NULL to draw a map with no path. So can cursor, frontier and visited */ void draw_map(Map map, size_t width, size_t height, Position start, Position goal, Position *cursor, Path path, char **visited, PositionPQ *frontier); /* Frees all the memory reserved for the map */ void map_free(Map map, size_t height); void print_map_out(Map map, size_t width, size_t height); void map_editor(Map *map, size_t *width, size_t *height, Position *start, Position *goal); void map_copy(Map src, size_t src_w, size_t src_h, Map dest, size_t dest_w, size_t dest_h); #endif /*MAP_H_ */