Naprawa błędu and -> or
This commit is contained in:
parent
9d1891524e
commit
e91bf45be5
12
agent.py
12
agent.py
@ -1,6 +1,7 @@
|
||||
from warehouse import Coordinates, Tile, Pack
|
||||
from queue import PriorityQueue
|
||||
from math import sqrt
|
||||
import pdb
|
||||
|
||||
class Node:
|
||||
def __init__(self, coord_x, coord_y):
|
||||
@ -44,7 +45,7 @@ class Agent:
|
||||
print(current_node.x, current_node.y)
|
||||
self.closed.append(current_node)
|
||||
if current_node.x == self.dest.x and current_node.y == self.dest.y:
|
||||
while current_node.x != start_node.x and current_node.y != start_node.y:
|
||||
while current_node.x != start_node.x or current_node.y != start_node.y:
|
||||
self.path.append(current_node)
|
||||
current_node = current_node.parent
|
||||
return True
|
||||
@ -62,12 +63,11 @@ class Agent:
|
||||
neighbour.h_cost = self.heuristic(neighbour, self.dest)
|
||||
neighbour.parent = current_node
|
||||
self.open.put((neighbour.g_cost, neighbour))
|
||||
# pdb.set_trace()
|
||||
return False
|
||||
|
||||
def heuristic(self, nodeA: Node, nodeB: Node):
|
||||
diff_x = pow(nodeB.x - nodeA.x, 2)
|
||||
diff_y = pow(nodeB.y - nodeA.y, 2)
|
||||
|
||||
def heuristic(self, start: Node, goal: Node):
|
||||
diff_x = pow(goal.x - start.x, 2)
|
||||
diff_y = pow(goal.y - start.y, 2)
|
||||
return round(sqrt(diff_x + diff_y), 3)
|
||||
|
||||
def check_if_open(self, node: Node):
|
||||
|
Loading…
Reference in New Issue
Block a user