int main() { char maps[1000][1000] = { { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 }, { 0, 0, 0, 1, 0, 1, 0, 1, 0, 1 }, { 1, 1, 1, 1, 0, 1, 0, 1, 0, 1 }, { 0, 0, 0, 1, 0, 0, 0, 1, 0, 1 }, { 0, 1, 0, 1, 1, 1, 1, 1, 0, 1 }, { 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }, { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 }, { 1, 1, 0, 0, 1, 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 }, }; // 搜索参数 AStar::Param param; param.width = 1000; param.height = 1000; param.allow_corner = false; param.start = AStar::Vec2(0, 0); param.end = AStar::Vec2(999, 999); param.is_canreach = [&](const AStar::Vec2 &pos)->bool { return maps[pos.y][pos.x] == 0; }; // 执行搜索 AStar as; Duration duration; auto path = as.search(param); std::cout << (path.empty() ? "路径未找到!" : "路径已找到!") << std::endl; std::cout << "本次寻路耗时" << duration.nano_seconds() << "纳秒" << std::endl; std::cout << '\n'; system("pause"); return 0; }
int main(int argc, char *argv[]) { char maps[10][10] = { { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 }, { 0, 0, 0, 1, 0, 1, 0, 1, 0, 1 }, { 1, 1, 1, 1, 0, 1, 0, 1, 0, 1 }, { 0, 0, 0, 1, 0, 0, 0, 1, 0, 1 }, { 0, 1, 0, 1, 1, 1, 1, 1, 0, 1 }, { 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }, { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 }, { 1, 1, 0, 0, 1, 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 }, }; // 搜索参数 AStar::Param param; param.width = 10; param.height = 10; param.corner = false; param.start = AStar::Vec2(0, 0); param.end = AStar::Vec2(9, 9); param.can_reach = [&](const AStar::Vec2 &pos)->bool { return maps[pos.y][pos.x] == 0; }; // 执行搜索 AStar as; Duration duration; auto path = as.find(param); std::cout << (path.empty() ? "路径未找到!" : "路径已找到!") << std::endl; std::cout << "本次寻路耗时" << duration.nano_seconds() << "纳秒" << std::endl; std::cout << '\n'; return 0; }