SI_InteligentnyWozekWidlowy/ForkliftAgent.py
2022-04-16 14:55:25 +02:00

59 lines
1.8 KiB
Python

from typing import Tuple
from mesa import Agent
from AgentBase import AgentBase
from data.Direction import Direction
from util.AgentIdFactory import AgentIdFactory
class ForkliftAgent(AgentBase):
def __init__(self, model):
super().__init__(model)
self.movement_queue = [Tuple[int, int]]
self.current_position = Tuple[int, int]
self.current_rotation = Direction.right
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()
def creation_log(self):
print("Created Forklift Agent [id: {}]".format(self.unique_id))