This commit is contained in:
andrzej 2020-04-23 19:43:51 +02:00
parent bb4800eb33
commit 716b4f0577
3 changed files with 18 additions and 11 deletions

View File

@ -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)
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

View File

@ -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()

View File

@ -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)