Naprawa błędu and -> or

This commit is contained in:
andrzej 2020-04-28 23:12:57 +02:00
parent 9d1891524e
commit e91bf45be5
2 changed files with 7 additions and 7 deletions

View File

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

View File

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