This commit is contained in:
2026-01-24 18:22:57 +01:00
parent 511816adea
commit 4465a756ef
5 changed files with 88 additions and 68 deletions
+13 -12
View File
@@ -53,7 +53,6 @@ auto main() -> int {
generator_2.setMultiplier((uint32_t)multiplier);
AStar::AStar<uint32_t, false> pathFinder;
pathFinder.setWorldSize({mapWidth, mapHeight});
pathFinder.setHeuristic(AStar::Heuristic::manhattan);
pathFinder.setDiagonalMovement(true);
@@ -95,8 +94,6 @@ auto main() -> int {
generator_2.setWeightedStrength(weighted_strength);
generator_2.setMultiplier((uint32_t)multiplier);
pathFinder.clear();
heightmap = generator_2.generate2dMeightmap(0, 0, 0, screenWidth, 0, screenHeight);
for (uint64_t x = 0; x < mapWidth; x++) {
@@ -108,18 +105,22 @@ auto main() -> int {
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});
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;
};
pathFinder.setHeuristic(AStar::Heuristic::manhattan);
auto start1 = std::chrono::high_resolution_clock::now();
auto path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1});
auto path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1}, {mapWidth, mapHeight}, isWalkable);
auto stop1 = std::chrono::high_resolution_clock::now();
if (path.empty()) {
std::cout << "Path not found" << std::endl;
@@ -134,7 +135,7 @@ auto main() -> int {
}
pathFinder.setHeuristic(AStar::Heuristic::euclidean);
path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1});
path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1}, {mapWidth, mapHeight}, isWalkable);
euclideanPathSize = path.size();
for (auto& i : path) {
@@ -143,7 +144,7 @@ auto main() -> int {
}
pathFinder.setHeuristic(AStar::Heuristic::octagonal);
path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1});
path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1}, {mapWidth, mapHeight}, isWalkable);
octagonalPathSize = path.size();
for (auto& i : path) {
@@ -152,7 +153,7 @@ auto main() -> int {
}
pathFinder.setHeuristic(AStar::Heuristic::chebyshev);
path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1});
path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1}, {mapWidth, mapHeight}, isWalkable);
chebyshevPathSize = path.size();
for (auto& i : path) {
@@ -161,7 +162,7 @@ auto main() -> int {
}
pathFinder.setHeuristic(AStar::Heuristic::euclideanNoSQR);
path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1});
path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1}, {mapWidth, mapHeight}, isWalkable);
euclideanNoSQRPathSize = path.size();
for (auto& i : path) {
@@ -170,7 +171,7 @@ auto main() -> int {
}
pathFinder.setHeuristic(AStar::Heuristic::dijkstra);
path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1});
path = pathFinder.findPath({0, 0}, {mapWidth - 1, mapHeight - 1}, {mapWidth, mapHeight}, isWalkable);
dijkstraPathSize = path.size();
for (auto& i : path) {