2020-04-07 01:18:04 +02:00
|
|
|
from warehouse import Coordinates, Tile
|
|
|
|
|
2020-04-02 15:25:15 +02:00
|
|
|
|
2020-04-04 22:03:15 +02:00
|
|
|
class Agent:
|
2020-04-06 15:12:50 +02:00
|
|
|
def __init__(self, start_x, start_y, assigned_warehouse, radius=5):
|
2020-04-02 15:25:15 +02:00
|
|
|
self.x = start_x
|
2020-04-04 22:03:15 +02:00
|
|
|
self.y = start_y
|
2020-04-07 01:18:04 +02:00
|
|
|
self.direction = 'down'
|
2020-04-06 15:12:50 +02:00
|
|
|
self.radius = radius
|
|
|
|
self.assigned_warehouse = assigned_warehouse
|
2020-04-06 16:11:57 +02:00
|
|
|
self.is_loaded = False
|
|
|
|
|
2020-04-07 01:18:04 +02:00
|
|
|
|
|
|
|
def move(self):
|
|
|
|
next_coords = self.get_next_move_coordinates()
|
|
|
|
can_move = self.check_if_can_move(next_coords)
|
|
|
|
if can_move:
|
|
|
|
self.x = next_coords.x
|
|
|
|
self.y = next_coords.y
|
|
|
|
|
|
|
|
def get_next_move_coordinates(self):
|
|
|
|
direction_moves = {
|
|
|
|
'up': self.move_up(),
|
|
|
|
'down': self.move_down(),
|
|
|
|
'left': self.move_left(),
|
|
|
|
'right': self.move_right()
|
|
|
|
}
|
|
|
|
next_coords = direction_moves.get(self.direction, Coordinates(self.x, self.y))
|
|
|
|
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
|
|
|
|
return tile_passable
|
|
|
|
|
2020-04-06 15:12:50 +02:00
|
|
|
def move_right(self):
|
2020-04-07 01:18:04 +02:00
|
|
|
pos_x = self.x + 1
|
|
|
|
if pos_x > self.assigned_warehouse.width - 1:
|
|
|
|
pos_x = self.assigned_warehouse.width - 1
|
|
|
|
return Coordinates(x=pos_x, y=self.y)
|
2020-04-06 15:12:50 +02:00
|
|
|
|
|
|
|
def move_left(self):
|
2020-04-07 01:18:04 +02:00
|
|
|
pos_x = self.x - 1
|
|
|
|
if pos_x < 0:
|
|
|
|
pos_x = 0
|
|
|
|
return Coordinates(x=pos_x, y=self.y)
|
2020-04-06 15:12:50 +02:00
|
|
|
|
|
|
|
def move_down(self):
|
2020-04-07 01:18:04 +02:00
|
|
|
pos_y = self.y + 1
|
|
|
|
if pos_y > self.assigned_warehouse.height - 1:
|
|
|
|
pos_y = self.assigned_warehouse.height - 1
|
|
|
|
return Coordinates(x=self.x, y=pos_y)
|
2020-04-06 15:12:50 +02:00
|
|
|
|
|
|
|
def move_up(self):
|
2020-04-07 01:18:04 +02:00
|
|
|
pos_y = self.y - 1
|
|
|
|
if pos_y < 0:
|
|
|
|
pos_y = 0
|
|
|
|
return Coordinates(x=self.x, y=pos_y)
|