From e91bf45be5f8d0dc58353f67f3be5eb1ded425f1 Mon Sep 17 00:00:00 2001 From: andrzej Date: Tue, 28 Apr 2020 23:12:57 +0200 Subject: [PATCH] =?UTF-8?q?Naprawa=20b=C5=82=C4=99du=20and=20->=20or?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent.py | 12 ++++++------ main.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/agent.py b/agent.py index d303b5e..4be00b6 100644 --- a/agent.py +++ b/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): diff --git a/main.py b/main.py index 44cffbf..5d43c83 100644 --- a/main.py +++ b/main.py @@ -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):