From 70d32f586ad17872809ca13f24d9fb36fb9ad213 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 7 Oct 2023 02:18:34 +0200 Subject: a --- src/path-search-dijkstra.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/path-search-dijkstra.cpp') diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp index eee01a47..404eb852 100644 --- a/src/path-search-dijkstra.cpp +++ b/src/path-search-dijkstra.cpp @@ -82,9 +82,36 @@ path_search_result path_search::Dijkstra(world& w, Vector2ub own_size, object_id if (from_offset_len >= eps && is_passable(w, ch0, bb0, own_id, p)) astar.push({from, from_offset, from, from_offset}, from_offset_len); + constexpr auto dirs = [] constexpr -> std::array { + constexpr auto sqrt_2 = math::sqrt(2.f); + std::array array = {{ + { -1, -1 }, + { 1, 1 }, + { -1, 1 }, + { 1, -1 }, + { -1, 0 }, + { 0, -1 }, + { 1, 0 }, + { 0, 1 }, + }}; + for (auto i = 0uz; i < array.size(); i++) + for (auto j = 0uz; j < i; j++) + fm_assert(array[i] != array[j]); + for (auto& vec : array) + { + if (vec.product() != 0) + vec = Vector2i(Vector2(vec) * path_search::div_size * sqrt_2); + else + vec *= path_search::div_size; + } + return array; + }(); + while (!astar.empty()) { - auto [prev, dist0] = astar.pop(); + auto [cur, dist0] = astar.pop(); + if (!astar.add_visited(cur)) + continue; } // todo... -- cgit v1.2.3