From e54769abdd290446fba30db1c9cd915e164eab61 Mon Sep 17 00:00:00 2001 From: andrzej Date: Fri, 1 May 2020 13:48:13 +0200 Subject: [PATCH] =?UTF-8?q?Poprawka,=20aby=20agent=20nie=20przeje=C5=BCd?= =?UTF-8?q?=C5=BCa=C5=82=20przez=20rega=C5=82y=20gdy=20jest=20za=C5=82adow?= =?UTF-8?q?any,=20poprawka=20warunku=20odpalenia=20rekurencyjnie=20find=5F?= =?UTF-8?q?nearest=5Frack=5Ffor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent.py | 8 +++----- main.py | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/agent.py b/agent.py index 0f174a9..a565fe9 100644 --- a/agent.py +++ b/agent.py @@ -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 diff --git a/main.py b/main.py index ee832a2..81d67b0 100644 --- a/main.py +++ b/main.py @@ -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):