Compare commits

...

2 Commits

Author SHA1 Message Date
va_alpatov
28e86fc355 tests hotfix 2026-04-11 20:23:08 +03:00
va_alpatov
93e7a9457a fixed pathfinding bug 2026-04-11 20:06:39 +03:00
2 changed files with 9 additions and 7 deletions

View File

@@ -87,11 +87,11 @@ namespace omath::pathfinding
const auto current_node = current_node_it->second; const auto current_node = current_node_it->second;
closed_list.emplace(current, current_node);
if (current == end_vertex) if (current == end_vertex)
return reconstruct_final_path(closed_list, current); return reconstruct_final_path(closed_list, current);
closed_list.emplace(current, current_node);
for (const auto& neighbor: nav_mesh.get_neighbors(current)) for (const auto& neighbor: nav_mesh.get_neighbors(current))
{ {
if (closed_list.contains(neighbor)) if (closed_list.contains(neighbor))

View File

@@ -40,8 +40,9 @@ TEST(AStarExtra, TrivialNeighbor)
nav.m_vertex_map[v2] = {v1}; nav.m_vertex_map[v2] = {v1};
const auto path = Astar::find_path(v1, v2, nav); const auto path = Astar::find_path(v1, v2, nav);
ASSERT_EQ(path.size(), 1u); ASSERT_EQ(path.size(), 2u);
EXPECT_EQ(path.front(), v2); EXPECT_EQ(path.front(), v1);
EXPECT_EQ(path.back(), v2);
} }
TEST(AStarExtra, StartEqualsGoal) TEST(AStarExtra, StartEqualsGoal)
@@ -101,7 +102,7 @@ TEST(AStarExtra, LongerPathAvoidsBlock)
constexpr Vector3<float> goal = idx(2, 1); constexpr Vector3<float> goal = idx(2, 1);
const auto path = Astar::find_path(start, goal, nav); const auto path = Astar::find_path(start, goal, nav);
ASSERT_FALSE(path.empty()); ASSERT_FALSE(path.empty());
EXPECT_EQ(path.front(), goal); EXPECT_EQ(path.back(), goal);
} }
TEST(AstarTests, TrivialDirectNeighborPath) TEST(AstarTests, TrivialDirectNeighborPath)
@@ -114,8 +115,9 @@ TEST(AstarTests, TrivialDirectNeighborPath)
nav.m_vertex_map.emplace(v2, std::vector<Vector3<float>>{v1}); nav.m_vertex_map.emplace(v2, std::vector<Vector3<float>>{v1});
const auto path = Astar::find_path(v1, v2, nav); const auto path = Astar::find_path(v1, v2, nav);
ASSERT_EQ(path.size(), 1u); ASSERT_EQ(path.size(), 2u);
EXPECT_EQ(path.front(), v2); EXPECT_EQ(path.front(), v1);
EXPECT_EQ(path.back(), v2);
} }
TEST(AstarTests, NoPathWhenDisconnected) TEST(AstarTests, NoPathWhenDisconnected)