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 typing import Tuple, List
from mesa import Agent
from AgentBase import AgentBase from AgentBase import AgentBase
from data.Direction import Direction from data.Direction import Direction
from util.AgentIdFactory import AgentIdFactory from decision.ActionType import ActionType
class ForkliftAgent(AgentBase): class ForkliftAgent(AgentBase):
def __init__(self, model): def __init__(self, model):
super().__init__(model) super().__init__(model)
# self.movement_queue = [Tuple[int, int]] self.movement_queue = []
# self.current_position = Tuple[int, int] self.current_position = Tuple[int, int]
self.current_rotation = Direction.right self.current_rotation = Direction.right
# def assign_new_movement_task(self, movement_list): def queue_movement_actions(self, movement_actions: List[ActionType]):
# self.movement_queue = [] self.movement_queue.extend(movement_actions)
#
# for m in movement_list: def move(self):
# self.movement_queue.append(m) if len(self.movement_queue) > 0:
# action = self.movement_queue.pop(0)
# print("Assigned new movement queue to forklift agent")
# if action == ActionType.ROTATE_UP:
# def get_proper_rotation(self, next_pos: Tuple[int, int]) -> Direction: print("rotate {} --> {}".format(self.current_rotation, action))
# self.current_rotation = Direction.top
# if next_pos[0] < self.current_position[0]:
# return Direction.left elif action == ActionType.ROTATE_RIGHT:
# elif next_pos[0] > self.current_position[0]: print("rotate {} --> {}".format(self.current_rotation, action))
# return Direction.right self.current_rotation = Direction.right
# elif next_pos[1] > self.current_position[1]:
# return Direction.top elif action == ActionType.ROTATE_DOWN:
# elif next_pos[1] < self.current_position[1]: print("rotate {} --> {}".format(self.current_rotation, action))
# return Direction.down self.current_rotation = Direction.down
# elif next_pos == self.current_position:
# return self.current_rotation elif action == ActionType.ROTATE_LEFT:
# print("rotate {} --> {}".format(self.current_rotation, action))
# def move(self): self.current_rotation = Direction.left
# if len(self.movement_queue) > 0:
# next_pos = self.movement_queue.pop(0) elif action == ActionType.MOVE:
# if self.current_rotation == Direction.top:
# dir = self.get_proper_rotation(next_pos) print("move {} --> {}".format(self.current_position, action))
# self.current_position = (self.current_position[0], self.current_position[1] + 1)
# if dir == self.current_rotation:
# print("move {} --> {}".format(self.current_position, next_pos)) elif self.current_rotation == Direction.down:
# self.current_position = next_pos print("move {} --> {}".format(self.current_position, action))
# else: self.current_position = (self.current_position[0], self.current_position[1] - 1)
# print("rotate {} --> {}".format(self.current_rotation, dir))
# self.current_rotation = dir elif self.current_rotation == Direction.right:
# self.movement_queue.insert(0, next_pos) 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") elif self.current_rotation == Direction.left:
# self.move() 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): def creation_log(self):
print("Created Forklift Agent [id: {}]".format(self.unique_id)) print("Created Forklift Agent [id: {}]".format(self.unique_id))

View File

@ -51,23 +51,13 @@ class GameModel(Model):
ActionType.NONE, []) 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_patch_agents()
self.place_walls_agents(graph.walls) self.place_walls_agents(graph.walls)
actions = pathFinder.getActionList() actions = pathFinder.getActionList()
print("PATHFINDING") print("PATHFINDING")
print(actions) print(actions)
self.forklift_agent.queue_movement_actions(actions)
def place_patch_agents(self): def place_patch_agents(self):
agent = PatchAgent(self, PatchType.pickUp) agent = PatchAgent(self, PatchType.pickUp)