SI_InteligentnyWozekWidlowy/ForkliftAgent.py
Aleksander Szamałek 522b29269d engine improvements
2022-05-22 16:27:36 +02:00

63 lines
2.6 KiB
Python

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