From 716b4f057783be1f934829a7260f02f41c3f913e Mon Sep 17 00:00:00 2001 From: andrzej Date: Thu, 23 Apr 2020 19:43:51 +0200 Subject: [PATCH] Poprawki --- agent.py | 24 ++++++++++++++++-------- main.py | 1 + warehouse.py | 4 +--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/agent.py b/agent.py index 1d529d7..7a45721 100644 --- a/agent.py +++ b/agent.py @@ -1,5 +1,5 @@ -from warehouse import Coordinates, Tile - +from warehouse import Coordinates, Tile, Pack +from attributes import PackStatus class Agent: def __init__(self, start_x, start_y, assigned_warehouse, radius=5): @@ -9,7 +9,7 @@ class Agent: self.radius = radius self.assigned_warehouse = assigned_warehouse self.is_loaded = False - + self.transported_package = None def demo_agent_move(self, demo_agent_step, demo_step_max=5): demo_agent_sign = 0 @@ -22,8 +22,6 @@ class Agent: demo_agent_sign = 1 self.direction = 'down' if not can_move: - # alt_move_left = - # alt_move_right = alternative_move = ('left' if self.check_if_can_move(self.move_left()) else None) or ('right' if self.check_if_can_move(self.move_right()) else self.direction) self.direction = alternative_move else: @@ -47,8 +45,6 @@ class Agent: return next_coords def check_if_can_move(self, next_coords: Coordinates): - # import pdb - # pdb.set_trace() next_tile = self.assigned_warehouse.tiles[next_coords.x][next_coords.y] tile_passable = isinstance(next_tile, Tile) and next_tile.category.passable tile_on_map = 0 <= next_coords.x < self.assigned_warehouse.width and 0 <= next_coords.y < self.assigned_warehouse.height @@ -76,4 +72,16 @@ class Agent: pos_y = self.y - 1 if pos_y < 0: pos_y = 0 - return Coordinates(x=self.x, y=pos_y) \ No newline at end of file + return Coordinates(x=self.x, y=pos_y) + + def package_ahead(self): + next_coords = self.get_next_move_coordinates() + potential_package = self.assigned_warehouse.tiles[next_coords.x][next_coords.y] + return isinstance(potential_package, Pack) and potential_package.status != PackStatus.STORED + + def pick_up_package(self, pack): + tile = pack.lays_on_field + self.assigned_warehouse.tiles[tile.x_position][tile.y_position] = tile + self.is_loaded = True + pack.lays_on_field = None + self.transported_package = pack \ No newline at end of file diff --git a/main.py b/main.py index e6cbc34..66d964e 100644 --- a/main.py +++ b/main.py @@ -87,6 +87,7 @@ class MainGameFrame: starting_x, starting_y = random.randrange(self.warehouse_map.width), random.randrange( self.warehouse_map.height) return starting_x, starting_y + if __name__ == '__main__': maingame = MainGameFrame() maingame.run() \ No newline at end of file diff --git a/warehouse.py b/warehouse.py index cbc13f7..9b98ecb 100644 --- a/warehouse.py +++ b/warehouse.py @@ -50,8 +50,7 @@ class Warehouse: self.generate_racks() self.open_isolated_areas() self.packages = self.place_packages(no_of_packages) - # import pdb - # pdb.set_trace() + def __str__(self): return "Magazyn {}x{}".format(self.width, self.height) @@ -71,7 +70,6 @@ class Warehouse: next_node = None self.tiles[node_x][node_y] = Tile('rack', node_x, node_y) q.put(node) - import pdb while not q.empty(): if next_node is not None: q.put(next_node)