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):
|
if isinstance(other, Node):
|
||||||
return self.x == other.x and self.y == self.y
|
return self.x == other.x and self.y == self.y
|
||||||
return False
|
return False
|
||||||
|
def __lt__(self, other):
|
||||||
|
return self.g_cost > other.g_cost
|
||||||
|
|
||||||
class Agent:
|
class Agent:
|
||||||
def __init__(self, start_x, start_y, assigned_warehouse, radius=5):
|
def __init__(self, start_x, start_y, assigned_warehouse, radius=5):
|
||||||
@ -29,8 +31,8 @@ class Agent:
|
|||||||
start_node = Node(self.x, self.y)
|
start_node = Node(self.x, self.y)
|
||||||
self.open.append(start_node)
|
self.open.append(start_node)
|
||||||
while self.open:
|
while self.open:
|
||||||
|
self.open = sorted(self.open)
|
||||||
current_node = self.open.pop()
|
current_node = self.open.pop()
|
||||||
print(current_node.x, current_node.y)
|
|
||||||
self.closed.append(current_node)
|
self.closed.append(current_node)
|
||||||
if current_node.x == self.dest.x and current_node.y == self.dest.y:
|
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 and current_node.y != start_node.y:
|
||||||
@ -59,20 +61,17 @@ class Agent:
|
|||||||
def check_if_open(self, nodeA: Node):
|
def check_if_open(self, nodeA: Node):
|
||||||
for node in self.open:
|
for node in self.open:
|
||||||
if node.x == nodeA.x and node.y == nodeA.y:
|
if node.x == nodeA.x and node.y == nodeA.y:
|
||||||
print("open")
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_if_closed(self, nodeA: Node):
|
def check_if_closed(self, nodeA: Node):
|
||||||
for node in self.closed:
|
for node in self.closed:
|
||||||
if node.x == nodeA.x and node.y == nodeA.y:
|
if node.x == nodeA.x and node.y == nodeA.y:
|
||||||
print("closed")
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_neighbours(self, node: Node):
|
def get_neighbours(self, node: Node):
|
||||||
neighbours = []
|
neighbours = []
|
||||||
print(neighbours)
|
|
||||||
if self.check_if_can_move(Coordinates(node.x + 1, node.y)):
|
if self.check_if_can_move(Coordinates(node.x + 1, node.y)):
|
||||||
neighbours.append(Node(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)):
|
if self.check_if_can_move(Coordinates(node.x - 1, node.y)):
|
||||||
@ -89,6 +88,7 @@ class Agent:
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
next = self.path.pop()
|
next = self.path.pop()
|
||||||
|
print(next.x, next.y)
|
||||||
self.x = next.x
|
self.x = next.x
|
||||||
self.y = next.y
|
self.y = next.y
|
||||||
|
|
||||||
|
2
main.py
2
main.py
@ -35,7 +35,7 @@ class MainGameFrame:
|
|||||||
self.draw_agent()
|
self.draw_agent()
|
||||||
self.agent.move()
|
self.agent.move()
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
self.clock.tick(5)
|
self.clock.tick(1)
|
||||||
|
|
||||||
def draw_floor(self):
|
def draw_floor(self):
|
||||||
for x in range(self.warehouse_map.width):
|
for x in range(self.warehouse_map.width):
|
||||||
|
Loading…
Reference in New Issue
Block a user