SI_InteligentnyWozekWidlowy/ForkliftAgent.py
2022-05-11 19:05:44 +02:00

62 lines
2.5 KiB
Python

from typing import Tuple, List
from AgentBase import AgentBase
from data.enum.Direction import Direction
from decision.ActionType import ActionType
class ForkliftAgent(AgentBase):
def __init__(self, model):
super().__init__(model)
self.movement_queue = []
self.current_position = Tuple[int, int]
self.current_rotation = Direction.right
def queue_movement_actions(self, movement_actions: List[ActionType]):
self.movement_queue.extend(movement_actions)
def move(self):
if len(self.movement_queue) > 0:
action = self.movement_queue.pop(0)
if action == ActionType.ROTATE_UP:
print("rotate {} --> {}".format(self.current_rotation, action))
self.current_rotation = Direction.top
elif action == ActionType.ROTATE_RIGHT:
print("rotate {} --> {}".format(self.current_rotation, action))
self.current_rotation = Direction.right
elif action == ActionType.ROTATE_DOWN:
print("rotate {} --> {}".format(self.current_rotation, action))
self.current_rotation = Direction.down
elif action == ActionType.ROTATE_LEFT:
print("rotate {} --> {}".format(self.current_rotation, action))
self.current_rotation = Direction.left
elif action == ActionType.MOVE:
if self.current_rotation == Direction.top:
print("move {} --> {}".format(self.current_position, action))
self.current_position = (self.current_position[0], self.current_position[1] + 1)
elif self.current_rotation == Direction.down:
print("move {} --> {}".format(self.current_position, action))
self.current_position = (self.current_position[0], self.current_position[1] - 1)
elif self.current_rotation == Direction.right:
print("move {} --> {}".format(self.current_position, action))
self.current_position = (self.current_position[0] + 1, self.current_position[1])
elif self.current_rotation == Direction.left:
print("move {} --> {}".format(self.current_position, action))
self.current_position = (self.current_position[0] - 1, self.current_position[1])
def step(self) -> None:
print("forklift step")
self.move()
def creation_log(self):
print("Created Forklift Agent [id: {}]".format(self.unique_id))