Poprawka, aby agent nie przejeżdżał przez regały gdy jest załadowany, poprawka warunku odpalenia rekurencyjnie find_nearest_rack_for

This commit is contained in:
andrzej 2020-05-01 13:48:13 +02:00
parent 06ce652016
commit e54769abdd
2 changed files with 5 additions and 7 deletions

View File

@ -2,7 +2,6 @@ from warehouse import Coordinates, Tile, Pack
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
@ -160,7 +159,7 @@ class Agent:
if not tile_on_map:
return False
next_tile = self.warehouse.tiles[next_coords.x][next_coords.y]
if not self.is_loaded:
if not self.is_loaded or (next_coords.x, next_coords.y) != (self.dest.x, self.dest.y):
tile_passable = isinstance(next_tile, Tile) and next_tile.category.passable
return tile_passable
@ -196,14 +195,13 @@ class Agent:
quarter_racks = [[t for t in row if t.category.name == "Rack" and not t.occupied and t.category.pack_size in accepted_weights] for row in quarter]
quarter_racks = [t for row in quarter_racks for t in row]
racks_costs = []
if not quarter_racks:
self.find_nearest_rack_for(package, expand_box+1)
for rack in quarter_racks:
new_node = Node(rack.x_position, rack.y_position)
cost = self.heuristic(start_node, new_node)
if cost > 0:
racks_costs.append((rack, cost))
rack = min(racks_costs, key=lambda l: l[1])[0]
rack = self.find_nearest_rack_for(package, expand_box + 1) if not racks_costs else min(racks_costs, key=lambda l: l[1])[0]
return rack

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, 20)
self.warehouse_map = warehouse.Warehouse(20, 20, 150, 40)
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()
@ -37,7 +37,7 @@ class MainGameFrame:
self.draw_agent()
self.agent.move()
pygame.display.update()
self.clock.tick(5)
self.clock.tick(8)
def draw_floor(self):
for x in range(self.warehouse_map.width):