Poprawka, by zamykało okno gdy wszystkie paczki są na swoich miejscach
This commit is contained in:
parent
7606871afb
commit
42f79f165a
8
agent.py
8
agent.py
@ -3,6 +3,8 @@ from queue import PriorityQueue
|
|||||||
from math import sqrt
|
from math import sqrt
|
||||||
from attributes import TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS, PackStatus, PackSize
|
from attributes import TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS, PackStatus, PackSize
|
||||||
import pdb
|
import pdb
|
||||||
|
import pygame
|
||||||
|
import sys
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, coord_x, coord_y, package=None, is_rack=False):
|
def __init__(self, coord_x, coord_y, package=None, is_rack=False):
|
||||||
@ -111,7 +113,6 @@ class Agent:
|
|||||||
def move(self):
|
def move(self):
|
||||||
dest_coords = (self.dest.x, self.dest.y)
|
dest_coords = (self.dest.x, self.dest.y)
|
||||||
if not self.path:
|
if not self.path:
|
||||||
print("chuj")
|
|
||||||
if not self.find_path():
|
if not self.find_path():
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@ -166,7 +167,7 @@ class Agent:
|
|||||||
packages_costs = []
|
packages_costs = []
|
||||||
start_node = Node(self.x, self.y)
|
start_node = Node(self.x, self.y)
|
||||||
if not self.warehouse.packages:
|
if not self.warehouse.packages:
|
||||||
return
|
return None
|
||||||
for package in self.warehouse.packages:
|
for package in self.warehouse.packages:
|
||||||
if package.status == PackStatus.STORED:
|
if package.status == PackStatus.STORED:
|
||||||
continue
|
continue
|
||||||
@ -174,6 +175,9 @@ class Agent:
|
|||||||
cost = self.heuristic(start_node, new_node)
|
cost = self.heuristic(start_node, new_node)
|
||||||
if cost > 0:
|
if cost > 0:
|
||||||
packages_costs.append((package, cost))
|
packages_costs.append((package, cost))
|
||||||
|
if not packages_costs:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
package = min(packages_costs, key=lambda l: l[1])[0]
|
package = min(packages_costs, key=lambda l: l[1])[0]
|
||||||
return package
|
return package
|
||||||
|
|
||||||
|
2
main.py
2
main.py
@ -21,7 +21,7 @@ class MainGameFrame:
|
|||||||
self.display = pygame.display.set_mode(WINDOW_SIZE)
|
self.display = pygame.display.set_mode(WINDOW_SIZE)
|
||||||
agent_radius = int(TILE_WIDTH/2)
|
agent_radius = int(TILE_WIDTH/2)
|
||||||
self.agent_tex = pygame.image.load('forklift.png')
|
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()
|
starting_x, starting_y = self.set_starting_agent_position()
|
||||||
self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map, agent_radius)
|
self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map, agent_radius)
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
|
Loading…
Reference in New Issue
Block a user