37 lines
1.9 KiB
C++
37 lines
1.9 KiB
C++
#ifdef NDEBUG
|
|
#undef NDEBUG
|
|
#endif
|
|
#include "../../src/port/UserInterface/AutoHuntNavigation.h"
|
|
#include <cassert>
|
|
#include <cstdio>
|
|
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<float>::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);
|
|
std::puts("autohunt navigation: direct, detour, sealed, thin wall, corners, budget, unloaded and coordinates passed");
|
|
}
|