SI_InteligentnyWozekWidlowy/ForkliftAgent.py

55 lines
1.7 KiB
Python
Raw Normal View History

2022-04-08 00:43:25 +02:00
from typing import Tuple
from mesa import Agent
from data.Direction import Direction
2022-03-06 22:16:21 +01:00
class ForkliftAgent(Agent):
def __init__(self, unique_id, model):
super().__init__(unique_id, model)
2022-04-08 00:43:25 +02:00
self.movement_queue = [Tuple[int, int]]
self.current_position = Tuple[int, int]
self.current_rotation = Direction.right
print("Created forklift Agent with ID: {}".format(unique_id))
def assign_new_movement_task(self, movement_list):
self.movement_queue = []
for m in movement_list:
self.movement_queue.append(m)
print("Assigned new movement queue to forklift agent")
def get_proper_rotation(self, next_pos: Tuple[int, int]) -> Direction:
if next_pos[0] < self.current_position[0]:
return Direction.left
elif next_pos[0] > self.current_position[0]:
return Direction.right
elif next_pos[1] > self.current_position[1]:
return Direction.top
elif next_pos[1] < self.current_position[1]:
return Direction.down
elif next_pos == self.current_position:
return self.current_rotation
def move(self):
if len(self.movement_queue) > 0:
next_pos = self.movement_queue.pop(0)
dir = self.get_proper_rotation(next_pos)
if dir == self.current_rotation:
print("move {} --> {}".format(self.current_position, next_pos))
self.current_position = next_pos
else:
print("rotate {} --> {}".format(self.current_rotation, dir))
self.current_rotation = dir
self.movement_queue.insert(0, next_pos)
def step(self) -> None:
print("forklift step")
self.move()