From 76f78b9e5853fb0d5f7f6493ee0aa4a411c691a8 Mon Sep 17 00:00:00 2001 From: tonywesoly Date: Thu, 12 May 2022 22:53:12 +0200 Subject: [PATCH] fixes --- Astar.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Astar.py b/Astar.py index 491b32f..4b494cd 100644 --- a/Astar.py +++ b/Astar.py @@ -46,6 +46,7 @@ class Pathfinding: # fringe = [] fringe = Min_heap() explored = [] + # explored = set() is_target_node_walkable = True if not target_node.walkable: @@ -64,16 +65,20 @@ class Pathfinding: # fringe.remove(current_node) explored.append(current_node) + # explored.add(current_node) if current_node.state == target_node.state: path = self.retrace_path(start_node,target_node) self.path = path + target_node.walkable = is_target_node_walkable return for neighbour in self.succ(current_node): - if not neighbour.walkable or neighbour in explored: - # if neighbour in explored: + neighbour_in_explored = [e for e in explored if e.state == neighbour.state] + if not neighbour.walkable or len(neighbour_in_explored) > 0: continue + # if neighbour in explored: + # continue new_movement_cost_to_neighbour = current_node.g_cost + self.get_distance(current_node,neighbour) # if new_movement_cost_to_neighbour < neighbour.g_cost or not neighbour in fringe: if new_movement_cost_to_neighbour < neighbour.g_cost or not fringe.contains(neighbour): @@ -83,7 +88,6 @@ class Pathfinding: # if not neighbour in fringe: if not fringe.contains(neighbour): fringe.insert(neighbour) - target_node.walkable = is_target_node_walkable def get_distance(self, node_a, node_b): # funckja liczy dystans dla odległości między dwoma nodami