Poprawka, by zamykało okno gdy wszystkie paczki są na swoich miejscach

This commit is contained in:
andrzej 2020-05-01 01:19:23 +02:00
parent 7606871afb
commit 42f79f165a
2 changed files with 7 additions and 3 deletions

View File

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

View File

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