fixes
This commit is contained in:
parent
b771ac0f00
commit
76f78b9e58
10
Astar.py
10
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
|
||||
|
Loading…
Reference in New Issue
Block a user