#define USEDEFAULTMAP hex035x035 #define hex006x006 "./Data/hex006x006.txt" #define hex014x006 "./Data/hex014x006.txt" #define hex035x035 "./Data/hex035x035.txt" #define hex054x045 "./Data/hex054x045.txt" #define hex098x098 "./Data/hex098x098.txt" #define hex113x083 "./Data/hex113x083.txt" #define OVERRIDE_DEFAULT_STARTING_DATA 0 #define DEFAULT_START_ROW 0 #define DEFAULT_START_COL 0 #define DEFAULT_GOAL_ROW ? #define DEFAULT_GOAL_COL ? #include #include #include "../TileSystem/Tile.h" #include "../TileSystem/TileMap.h" #include "../platform.h" #include "../PriorityQueue.h" namespace algorithms { class PathSearch { private: struct SearchNode { Tile* tile; std::vector neighbors; }; struct PlannerNode { SearchNode* searchNode; PlannerNode* parent; float finalCost = 0; float heuristicCost = 0; float givenCost = 0; }; #define DISTANCE(x1,y1, x2, y2) ( std::sqrt( std::pow(x2 - x1, 2) + std::pow(y2 - y1, 2))) struct GreedyComparator { bool operator()(const PlannerNode* lhs, const PlannerNode* rhs) { return lhs->finalCost > rhs->finalCost; } }; std::unordered_map nodes; std::unordered_map visited; PriorityQueue queue; TileMap* tileMap; bool done = false; SearchNode* startingTile; SearchNode* endingTile; public: DLLEXPORT PathSearch(); DLLEXPORT ~PathSearch(); DLLEXPORT void initialize(TileMap* _tileMap); DLLEXPORT void enter(int startRow, int startColumn, int goalRow, int goalColumn); DLLEXPORT bool isDone() const; DLLEXPORT void update(long timeslice); DLLEXPORT std::vector const getSolution() const; DLLEXPORT void exit(); DLLEXPORT void shutdown(); }; }