From 42f79f165aafdaabf766fc92170b310e6819f072 Mon Sep 17 00:00:00 2001 From: andrzej Date: Fri, 1 May 2020 01:19:23 +0200 Subject: [PATCH] =?UTF-8?q?Poprawka,=20by=20zamyka=C5=82o=20okno=20gdy=20w?= =?UTF-8?q?szystkie=20paczki=20s=C4=85=20na=20swoich=20miejscach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent.py | 8 ++++++-- main.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/agent.py b/agent.py index 0e97dfd..86ee113 100644 --- a/agent.py +++ b/agent.py @@ -3,6 +3,8 @@ from queue import PriorityQueue from math import sqrt from attributes import TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS, PackStatus, PackSize import pdb +import pygame +import sys class Node: def __init__(self, coord_x, coord_y, package=None, is_rack=False): @@ -111,7 +113,6 @@ class Agent: def move(self): dest_coords = (self.dest.x, self.dest.y) if not self.path: - print("chuj") if not self.find_path(): return else: @@ -166,7 +167,7 @@ class Agent: packages_costs = [] start_node = Node(self.x, self.y) if not self.warehouse.packages: - return + return None for package in self.warehouse.packages: if package.status == PackStatus.STORED: continue @@ -174,6 +175,9 @@ class Agent: cost = self.heuristic(start_node, new_node) if cost > 0: packages_costs.append((package, cost)) + if not packages_costs: + pygame.quit() + sys.exit() package = min(packages_costs, key=lambda l: l[1])[0] return package diff --git a/main.py b/main.py index 11337b4..995ce72 100644 --- a/main.py +++ b/main.py @@ -21,7 +21,7 @@ class MainGameFrame: self.display = pygame.display.set_mode(WINDOW_SIZE) agent_radius = int(TILE_WIDTH/2) self.agent_tex = pygame.image.load('forklift.png') - self.warehouse_map = warehouse.Warehouse(20, 20, 150, 25) + self.warehouse_map = warehouse.Warehouse(20, 20, 150, 2) starting_x, starting_y = self.set_starting_agent_position() self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map, agent_radius) self.clock = pygame.time.Clock()