#ifndef ALGORITHM_H #define ALGORITHM_H #include #include #include //creates a game, fills it with walls and empty fields struct game make_maze(size_t y, size_t x); typedef darray(struct point) pointarr; //algorithm terminates with no path if target is not found within maxdist //result contains target as well as the source point //so even if next to the target, the result arr is at least 2 items big pointarr astar(struct game *g, struct point start, struct point target, size_t maxdist); #define insight(g,p1,p2) (insight_(g,p1,p2) || insight_(g,p2,p1)) static inline bool insight_(const struct game *g, struct point p1, struct point p2) { size_t view_left = SIGHT_RANGE; //FIXME: range seems too long ingame while(!pointeq(p1,p2)) { if(p1.x != p2.x) p2.x += sign(p1.x - p2.x); if(p1.y != p2.y) p2.y += sign(p1.y - p2.y); if(!(view_left--) || game_at(g, p2)->u->ground.type == WALL) return false; } return true; } #endif //ALGORITHM_H