SI_InteligentnyWozekWidlowy/ForkliftAgent.py

62 lines
2.5 KiB
Python
Raw Normal View History

2022-04-28 02:09:41 +02:00
from typing import Tuple, List
2022-04-08 00:43:25 +02:00
2022-04-16 14:55:25 +02:00
from AgentBase import AgentBase
2022-05-11 19:05:44 +02:00
from data.enum.Direction import Direction
2022-04-28 02:09:41 +02:00
from decision.ActionType import ActionType
2022-03-06 22:16:21 +01:00
2022-04-16 14:55:25 +02:00
class ForkliftAgent(AgentBase):
2022-03-06 22:16:21 +01:00
2022-04-16 14:55:25 +02:00
def __init__(self, model):
super().__init__(model)
2022-04-28 02:09:41 +02:00
self.movement_queue = []
self.current_position = Tuple[int, int]
2022-04-08 00:43:25 +02:00
self.current_rotation = Direction.right
2022-04-28 02:09:41 +02:00
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()
2022-04-16 14:55:25 +02:00
def creation_log(self):
print("Created Forklift Agent [id: {}]".format(self.unique_id))