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.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_passable = True
if not tile_on_map:
@ -185,13 +185,17 @@ class Agent:
if cost > 0:
packages_costs.append((package, cost))
if not packages_costs:
pygame.quit()
sys.exit()
return
# pygame.quit()
# sys.exit()
package = min(packages_costs, key=lambda l: l[1])[0]
return package
def find_nearest_rack_for(self, package, expand_box=0):
weight = package.size
storage = "Rack"
if package.category == "freezed":
storage = "Fridge"
start_node = Node(self.x, self.y)
quarter_x = int(self.warehouse.width/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
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_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]
racks_costs = []
for rack in quarter_racks:

View File

@ -26,7 +26,7 @@ class MainGameFrame:
agent_radius = int(TILE_WIDTH/2)
self.agent_tex = pygame.image.load('forklift.png')
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()
self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map, agent_radius)
self.clock = pygame.time.Clock()
@ -43,7 +43,7 @@ class MainGameFrame:
self.draw_nums()
self.agent.move()
pygame.display.update()
self.clock.tick(8)
self.clock.tick(5)
def draw_floor(self):
for x in range(self.warehouse_map.width):
@ -91,7 +91,7 @@ class MainGameFrame:
for cell in row:
if cell.category.name in self.warehouse_map.storage_types:
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):
rotated = pygame.transform.rotate(self.agent_tex, DIRECTION_ANGLES.get(self.agent.direction))

View File

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