algorithm.h
| 1 | #ifndef ALGORITHM_H |
| 2 | #define ALGORITHM_H |
| 3 | #include <stddef.h> |
| 4 | #include <game.h> |
| 5 | #include <config.h> |
| 6 | |
| 7 | //creates a game, fills it with walls and empty fields |
| 8 | struct game make_maze(size_t y, size_t x); |
| 9 | typedef darray(struct point) pointarr; |
| 10 | |
| 11 | //algorithm terminates with no path if target is not found within maxdist |
| 12 | //result contains target as well as the source point |
| 13 | //so even if next to the target, the result arr is at least 2 items big |
| 14 | pointarr astar(struct game *g, struct point start, struct point target, size_t maxdist); |
| 15 | #define insight(g,p1,p2) (insight_(g,p1,p2) || insight_(g,p2,p1)) |
| 16 | static inline bool insight_(const struct game *g, struct point p1, struct point p2) |
| 17 | { |
| 18 | size_t view_left = SIGHT_RANGE; //FIXME: range seems too long ingame |
| 19 | while(!pointeq(p1,p2)) |
| 20 | { |
| 21 | if(p1.x != p2.x) |
| 22 | p2.x += sign(p1.x - p2.x); |
| 23 | if(p1.y != p2.y) |
| 24 | p2.y += sign(p1.y - p2.y); |
| 25 | if(!(view_left--) || game_at(g, p2)->u->ground.type == WALL) |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | #endif //ALGORITHM_H |
| 33 |