SI_InteligentnyWozekWidlowy/ForkliftAgent.py

63 lines
2.6 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-05-22 16:27:36 +02:00
from decision.Action import Action
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-05-22 16:27:36 +02:00
self.action_queue: List[Action] = []
2022-04-28 02:09:41 +02:00
self.current_position = Tuple[int, int]
2022-04-08 00:43:25 +02:00
self.current_rotation = Direction.right
2022-05-22 16:27:36 +02:00
def queue_movement_actions(self, movement_actions: List[Action]):
self.action_queue.extend(movement_actions)
2022-04-28 02:09:41 +02:00
def move(self):
2022-05-22 16:27:36 +02:00
if len(self.action_queue) > 0:
action = self.action_queue.pop(0)
action_type = action.action_type
2022-04-28 02:09:41 +02:00
2022-05-22 16:27:36 +02:00
if action_type == ActionType.ROTATE_UP:
print("rotate {} --> {}".format(self.current_rotation, action_type))
2022-04-28 02:09:41 +02:00
self.current_rotation = Direction.top
2022-05-22 16:27:36 +02:00
elif action_type == ActionType.ROTATE_RIGHT:
print("rotate {} --> {}".format(self.current_rotation, action_type))
2022-04-28 02:09:41 +02:00
self.current_rotation = Direction.right
2022-05-22 16:27:36 +02:00
elif action_type == ActionType.ROTATE_DOWN:
print("rotate {} --> {}".format(self.current_rotation, action_type))
2022-04-28 02:09:41 +02:00
self.current_rotation = Direction.down
2022-05-22 16:27:36 +02:00
elif action_type == ActionType.ROTATE_LEFT:
print("rotate {} --> {}".format(self.current_rotation, action_type))
2022-04-28 02:09:41 +02:00
self.current_rotation = Direction.left
2022-05-22 16:27:36 +02:00
elif action_type == ActionType.MOVE:
2022-04-28 02:09:41 +02:00
if self.current_rotation == Direction.top:
2022-05-22 16:27:36 +02:00
print("move {} --> {}".format(self.current_position, action_type))
2022-04-28 02:09:41 +02:00
self.current_position = (self.current_position[0], self.current_position[1] + 1)
elif self.current_rotation == Direction.down:
2022-05-22 16:27:36 +02:00
print("move {} --> {}".format(self.current_position, action_type))
2022-04-28 02:09:41 +02:00
self.current_position = (self.current_position[0], self.current_position[1] - 1)
elif self.current_rotation == Direction.right:
2022-05-22 16:27:36 +02:00
print("move {} --> {}".format(self.current_position, action_type))
2022-04-28 02:09:41 +02:00
self.current_position = (self.current_position[0] + 1, self.current_position[1])
elif self.current_rotation == Direction.left:
2022-05-22 16:27:36 +02:00
print("move {} --> {}".format(self.current_position, action_type))
2022-04-28 02:09:41 +02:00
self.current_position = (self.current_position[0] - 1, self.current_position[1])
def step(self) -> None:
self.move()
2022-04-16 14:55:25 +02:00
def creation_log(self):
print("Created Forklift Agent [id: {}]".format(self.unique_id))