This commit is contained in:
Yakudami 2020-04-28 01:24:12 +02:00
parent 7934ed0d9d
commit b32451379b
2 changed files with 5 additions and 5 deletions

View File

@ -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

View File

@ -35,7 +35,7 @@ class MainGameFrame:
self.draw_agent()
self.agent.move()
pygame.display.update()
self.clock.tick(5)
self.clock.tick(1)
def draw_floor(self):
for x in range(self.warehouse_map.width):