#ifdef NDEBUG #undef NDEBUG #endif #include "../../src/port/UserInterface/AutoHuntNavigation.h" #include #include using namespace AutoHuntNavigation; int main() { auto free=[](Point) { return true; }; auto direct=FindPath({0,0},{1000,0},100,free); assert(direct.size()==1 && direct.back().x==1000); // A solid wall must be bypassed through its opening, with every returned segment traversable. auto wall=[](Point p) { return !(p.x>=400 && p.x<=600 && p.y>-500 && p.y<500); }; auto detour=FindPath({0,0},{1000,0},100,wall); assert(detour.size()>1); Point prev{0,0}; bool turned=false; for (auto p:detour) { assert(Segment(prev,p,wall)); turned |= std::abs(p.y)>=500; prev=p; } assert(turned && Distance(prev,{1000,0})<=100); auto sealed=[](Point p) { return p.x<400 || p.x>600; }; assert(FindPath({0,0},{1000,0},100,sealed).empty()); // A nearby target across a thin wall is not reachable merely because it is in attack range. auto thin=[](Point p) { return p.x<30 || p.x>70; }; assert(FindPath({0,0},{100,0},150,thin).empty()); // Corner cutting cannot pass between touching wall cells. auto diagonal=[](Point p) { return (p.x<50 && p.y<50) || (p.x>=50 && p.y>=50); }; assert(FindPath({0,0},{200,200},0,diagonal).empty()); assert(FindPath({0,0},{1000,0},100,wall,1).empty()); assert(FindPath({0,0},{1000,0},100,[](Point){return false;}).empty()); assert(FindPath({0,0},{std::numeric_limits::quiet_NaN(),0},100,free).empty()); // Start/finish and negative map-relative coordinates retain their exact positions. auto negative=FindPath({-23,-47},{-1023,-47},0,free); assert(negative.size()==1 && negative.back().x==-1023 && negative.back().y==-47); // A large target standing in unwalkable cells (a hydra on the water) is reached at its edge. auto lake=[](Point p) { return Distance(p,{1000,0})>300; }; assert(FindPath({0,0},{1000,0},100,lake).empty()); auto shore=FindPath({0,0},{1000,0},450,lake,3500,350); assert(!shore.empty()); prev={0,0}; for (auto p:shore) { assert(lake(p) && Segment(prev,p,lake)); prev=p; } assert(Distance(prev,{1000,0})<=450); auto around=FindPath({0,0},{1000,0},450,[&](Point p) { return lake(p) && wall(p); },3500,350); assert(around.size()>1 && Distance(around.back(),{1000,0})<=450); // Captured snow floor 1: knockback put the actor in blocked terrain row // 225, 90 units from monsters in clear row 224. The old exact-start-only // exemption rejected every intermediate sample and stalled both combat // selection and recovery movement. const Point knocked{18730.742f,22544.762f}, enemy{18730.742f,22454.762f}; auto attributes=[](Point p) { if (p.x<0 || p.y<0) return -1; return p.y>=22500 ? 1 : 0; }; auto oldFootprint=[&](Point p) { if (Distance(p,knocked)<1.f) return true; for (const Point offset : {Point{0,0},{25,0},{-25,0},{0,25},{0,-25}}) if (attributes({p.x+offset.x,p.y+offset.y})!=0) return false; return true; }; assert(FindPath(knocked,enemy,100,oldFootprint).empty()); auto terrain=TerrainWalkable(knocked,attributes,100); auto footprint=[&](Point p) { for (const Point offset : {Point{0,0},{25,0},{-25,0},{0,25},{0,-25}}) if (!terrain({p.x+offset.x,p.y+offset.y})) return false; return true; }; assert(FindPath(knocked,enemy,100,footprint).size()==1); assert(FindPath(knocked,enemy,0,footprint,3500,0,true).size()==1); assert(FindPath(knocked,{18730,22800},0,footprint).empty()); auto clearStart=TerrainWalkable({18730,22400},attributes,100); assert(!clearStart({18730,22510})); auto unloaded=TerrainWalkable(knocked,[](Point){return -1;},100); assert(FindPath(knocked,enemy,0,unloaded).empty()); // A blocked combat sight line must not explore the room looking for a // detour that the caller immediately rejects. Simulate 240 crowded targets. int normalQueries=0, sightQueries=0; for (int i=0;i<240;++i) { auto full=FindPath({0,0},{1000,float(i%5)},0,[&](Point p){++normalQueries;return wall(p);}); auto sight=FindPath({0,0},{1000,float(i%5)},0,[&](Point p){++sightQueries;return wall(p);},3500,0,true); assert((full.size()==1)==(sight.size()==1)); } assert(sightQueries*10 %d (same direct-line decisions)\n",normalQueries,sightQueries); std::puts("autohunt navigation: direct, detour, sealed, thin wall, corners, budget, unloaded, coordinates and large targets passed"); }