mirror of
https://github.com/bensuperpc/astar.git
synced 2026-05-05 19:05:24 +02:00
new1
This commit is contained in:
@@ -49,7 +49,6 @@ static void astar_bench(benchmark::State& state) {
|
||||
|
||||
AStar::AStar<CoordinateType, false> pathFinder;
|
||||
benchmark::DoNotOptimize(pathFinder);
|
||||
pathFinder.setWorldSize({mapWidth, mapHeight});
|
||||
pathFinder.setHeuristic(AStar::Heuristic::euclidean);
|
||||
pathFinder.setDiagonalMovement(true);
|
||||
|
||||
@@ -62,15 +61,12 @@ static void astar_bench(benchmark::State& state) {
|
||||
blocks[index] = 0;
|
||||
} else {
|
||||
blocks[index] = 1;
|
||||
pathFinder.addObstacle({static_cast<int32_t>(x), static_cast<int32_t>(y)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
blocks[0] = 0;
|
||||
pathFinder.removeObstacle({0, 0});
|
||||
blocks[mapWidth * mapHeight - 1] = 0;
|
||||
pathFinder.removeObstacle({mapWidth - 1, mapHeight - 1});
|
||||
|
||||
AStar::Vec2i source(0, 0);
|
||||
AStar::Vec2i target(mapWidth - 1, mapHeight - 1);
|
||||
@@ -78,8 +74,15 @@ static void astar_bench(benchmark::State& state) {
|
||||
std::vector<AStar::Vec2i> path;
|
||||
benchmark::DoNotOptimize(path);
|
||||
|
||||
std::function<bool(AStar::Vec2i)> isWalkable = [&blocks, mapWidth, mapHeight](AStar::Vec2i pos) {
|
||||
if (pos.x < 0 || pos.x >= mapWidth || pos.y < 0 || pos.y >= mapHeight) {
|
||||
return false;
|
||||
}
|
||||
return blocks[pos.x + pos.y * mapWidth] == 0;
|
||||
};
|
||||
|
||||
for (auto _ : state) {
|
||||
path = pathFinder.findPath(source, target);
|
||||
path = pathFinder.findPath(source, target, {mapWidth, mapHeight}, isWalkable);
|
||||
state.PauseTiming();
|
||||
if (path.size() == 0) {
|
||||
state.SkipWithError("No path found");
|
||||
|
||||
Reference in New Issue
Block a user