implemented movement on states

This commit is contained in:
Aleksander Szamałek 2022-04-28 02:09:41 +02:00
parent 88d2ebe087
commit f6a07386a8
2 changed files with 48 additions and 55 deletions

View File

@ -1,58 +1,61 @@
from typing import Tuple
from mesa import Agent
from typing import Tuple, List
from AgentBase import AgentBase
from data.Direction import Direction
from util.AgentIdFactory import AgentIdFactory
from decision.ActionType import ActionType
class ForkliftAgent(AgentBase):
def __init__(self, model):
super().__init__(model)
# self.movement_queue = [Tuple[int, int]]
# self.current_position = Tuple[int, int]
self.movement_queue = []
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 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))

View File

@ -51,23 +51,13 @@ class GameModel(Model):
ActionType.NONE, [])
)
# came_from, cost_so_far = a_star_search(graph, start, goal)
# draw_grid(graph, point_to=came_from, start=start, goal=goal)
#
# path = map(lambda t: (t[0], inverse_y(height, t[1])),
# reconstruct_path(came_from=came_from, start=start, goal=goal))
#
# print("cam from: {}".format(came_from))
# print("costerino: {}".format(cost_so_far))
# draw_grid(graph, path=reconstruct_path(came_from, start=start, goal=goal))
# self.forklift_agent.assign_new_movement_task(path)
self.place_patch_agents()
self.place_walls_agents(graph.walls)
actions = pathFinder.getActionList()
print("PATHFINDING")
print(actions)
self.forklift_agent.queue_movement_actions(actions)
def place_patch_agents(self):
agent = PatchAgent(self, PatchType.pickUp)