This commit is contained in:
andrzej 2020-05-07 16:42:19 +02:00
parent b9fa16a5a9
commit ba69a06e3f
3 changed files with 16 additions and 8 deletions

View File

@ -162,7 +162,7 @@ class Agent:
self.path.append(next) self.path.append(next)
self.closed = [] self.closed = []
def check_if_can_move(self, next_coords: Coordinates, rack_searching=False): def check_if_can_move(self, next_coords: Coordinates):
tile_on_map = 0 <= next_coords.x < self.warehouse.width and 0 <= next_coords.y < self.warehouse.height tile_on_map = 0 <= next_coords.x < self.warehouse.width and 0 <= next_coords.y < self.warehouse.height
tile_passable = True tile_passable = True
if not tile_on_map: if not tile_on_map:
@ -185,13 +185,17 @@ class Agent:
if cost > 0: if cost > 0:
packages_costs.append((package, cost)) packages_costs.append((package, cost))
if not packages_costs: if not packages_costs:
pygame.quit() return
sys.exit() # 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
def find_nearest_rack_for(self, package, expand_box=0): def find_nearest_rack_for(self, package, expand_box=0):
weight = package.size weight = package.size
storage = "Rack"
if package.category == "freezed":
storage = "Fridge"
start_node = Node(self.x, self.y) start_node = Node(self.x, self.y)
quarter_x = int(self.warehouse.width/4) + expand_box quarter_x = int(self.warehouse.width/4) + expand_box
quarter_y = int(self.warehouse.height/4) + expand_box quarter_y = int(self.warehouse.height/4) + expand_box
@ -200,7 +204,7 @@ class Agent:
start_quarter_y = self.y - quarter_y if self.y - quarter_y > 0 else 0 start_quarter_y = self.y - quarter_y if self.y - quarter_y > 0 else 0
end_quarter_y = self.y + quarter_y if self.y + quarter_y < self.warehouse.height else self.warehouse.height - 1 end_quarter_y = self.y + quarter_y if self.y + quarter_y < self.warehouse.height else self.warehouse.height - 1
quarter = [row[start_quarter_y:end_quarter_y] for row in self.warehouse.tiles[start_quarter_x:end_quarter_x]] quarter = [row[start_quarter_y:end_quarter_y] for row in self.warehouse.tiles[start_quarter_x:end_quarter_x]]
quarter_racks = [[t for t in row if t.category.name in self.warehouse.storage_types and t.capacity >= weight] for row in quarter] quarter_racks = [[t for t in row if t.category.name == storage and t.capacity >= weight] for row in quarter]
quarter_racks = [t for row in quarter_racks for t in row] quarter_racks = [t for row in quarter_racks for t in row]
racks_costs = [] racks_costs = []
for rack in quarter_racks: for rack in quarter_racks:

View File

@ -26,7 +26,7 @@ class MainGameFrame:
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.font = pygame.font.Font('freesansbold.ttf', 16) self.font = pygame.font.Font('freesansbold.ttf', 16)
self.warehouse_map = warehouse.Warehouse(20, 20, 150, 40) self.warehouse_map = warehouse.Warehouse(20, 20, 250, 20)
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()
@ -43,7 +43,7 @@ class MainGameFrame:
self.draw_nums() self.draw_nums()
self.agent.move() self.agent.move()
pygame.display.update() pygame.display.update()
self.clock.tick(8) self.clock.tick(5)
def draw_floor(self): def draw_floor(self):
for x in range(self.warehouse_map.width): for x in range(self.warehouse_map.width):
@ -91,7 +91,7 @@ class MainGameFrame:
for cell in row: for cell in row:
if cell.category.name in self.warehouse_map.storage_types: if cell.category.name in self.warehouse_map.storage_types:
text_surface = self.font.render(str(cell.capacity), True, (0, 0, 0)) text_surface = self.font.render(str(cell.capacity), True, (0, 0, 0))
self.display.blit(text_surface, ((cell.x_position * TILE_WIDTH) + 1, (cell.y_position * TILE_HEIGHT) + 6)) self.display.blit(text_surface, ((cell.x_position * TILE_WIDTH) + 6, (cell.y_position * TILE_HEIGHT) + 6))
def draw_agent(self): def draw_agent(self):
rotated = pygame.transform.rotate(self.agent_tex, DIRECTION_ANGLES.get(self.agent.direction)) rotated = pygame.transform.rotate(self.agent_tex, DIRECTION_ANGLES.get(self.agent.direction))

View File

@ -29,6 +29,9 @@ class Pack:
if self.lays_on_field.category.name in ['Floor', 'FridgeFloor']: if self.lays_on_field.category.name in ['Floor', 'FridgeFloor']:
status = PackStatus.LOOSE status = PackStatus.LOOSE
elif self.lays_on_field.category.name in ['Rack', 'Fridge']: elif self.lays_on_field.category.name in ['Rack', 'Fridge']:
if self.category == 'freezed' and self.lays_on_field.category.name != 'Fridge':
status = PackStatus.STORED_BAD_LOCATION
else:
status = PackStatus.STORED status = PackStatus.STORED
return status return status
@ -198,6 +201,7 @@ class Warehouse:
categ_seed = random.random() categ_seed = random.random()
if categ_seed > 0.8: if categ_seed > 0.8:
new_package.category = "freezed" new_package.category = "freezed"
new_package.set_status()
new_package.size = random.randrange(1, 10) new_package.size = random.randrange(1, 10)
if package_field.category.name in self.storage_types: if package_field.category.name in self.storage_types:
package_field.capacity -= new_package.size package_field.capacity -= new_package.size