fixes
This commit is contained in:
parent
7934ed0d9d
commit
b32451379b
8
agent.py
8
agent.py
@ -11,6 +11,8 @@ class Node:
|
||||
if isinstance(other, Node):
|
||||
return self.x == other.x and self.y == self.y
|
||||
return False
|
||||
def __lt__(self, other):
|
||||
return self.g_cost > other.g_cost
|
||||
|
||||
class Agent:
|
||||
def __init__(self, start_x, start_y, assigned_warehouse, radius=5):
|
||||
@ -29,8 +31,8 @@ class Agent:
|
||||
start_node = Node(self.x, self.y)
|
||||
self.open.append(start_node)
|
||||
while self.open:
|
||||
self.open = sorted(self.open)
|
||||
current_node = self.open.pop()
|
||||
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:
|
||||
@ -59,20 +61,17 @@ class Agent:
|
||||
def check_if_open(self, nodeA: Node):
|
||||
for node in self.open:
|
||||
if node.x == nodeA.x and node.y == nodeA.y:
|
||||
print("open")
|
||||
return True
|
||||
return False
|
||||
|
||||
def check_if_closed(self, nodeA: Node):
|
||||
for node in self.closed:
|
||||
if node.x == nodeA.x and node.y == nodeA.y:
|
||||
print("closed")
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_neighbours(self, node: Node):
|
||||
neighbours = []
|
||||
print(neighbours)
|
||||
if self.check_if_can_move(Coordinates(node.x + 1, node.y)):
|
||||
neighbours.append(Node(node.x + 1, node.y))
|
||||
if self.check_if_can_move(Coordinates(node.x - 1, node.y)):
|
||||
@ -89,6 +88,7 @@ class Agent:
|
||||
return
|
||||
else:
|
||||
next = self.path.pop()
|
||||
print(next.x, next.y)
|
||||
self.x = next.x
|
||||
self.y = next.y
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user