SI_InteligentnyWozekWidlowy/main.py
Aleksander Szamałek 59676e176a Pathfinder
2022-04-08 00:43:25 +02:00

66 lines
2.1 KiB
Python

import random
from mesa.visualization.ModularVisualization import ModularServer
from mesa.visualization.modules import CanvasGrid
from ForkliftAgent import ForkliftAgent
from GameModel import GameModel
from PatchAgent import PatchAgent
from PatchType import PatchType
from data.Direction import Direction
from util.PathDefinitions import GridWithWeights
colors = [
'blue', 'cyan', 'orange', 'yellow', 'magenta', 'purple', '#103d3e', '#9fc86c',
'#b4c2ed', '#31767d', '#31a5fa', '#ba96e0', '#fef3e4', '#6237ac', '#f9cacd', '#1e8123'
]
def agent_portrayal(agent):
if isinstance(agent, ForkliftAgent):
shape = ""
if agent.current_rotation == Direction.top:
shape = "img/image_top.png"
elif agent.current_rotation == Direction.right:
shape = "img/image_right.png"
elif agent.current_rotation == Direction.down:
shape = "img/image_down.png"
elif agent.current_rotation == Direction.left:
shape = "img/image_left.png"
portrayal = {"Shape": shape, "scale": 1.0, "Layer": 0}
if isinstance(agent, PatchAgent):
color = colors[0]
if agent.type == PatchType.dropOff:
portrayal = {"Shape": "img/truck.png", "scale": 1.0, "Layer": 0}
elif agent.type == PatchType.pickUp:
portrayal = {"Shape": "img/okB00mer.png", "scale": 1.0, "Layer": 0}
else:
color = colors[random.randrange(13) + 3]
portrayal = {"Shape": "rect",
"Filled": "true",
"Layer": 0,
"Color": color,
"w": 1,
"h": 1}
return portrayal
base = 512
gridWidth = 10
gridHeight = 10
scale = base / gridWidth
diagram4 = GridWithWeights(gridWidth, gridHeight)
diagram4.walls = []
grid = CanvasGrid(agent_portrayal, gridWidth, gridHeight, scale * gridWidth, scale * gridHeight)
server = ModularServer(GameModel,
[grid],
"Automatyczny Wózek Widłowy",
{"width": gridHeight, "height": gridWidth, "graph": diagram4})
server.port = 8888
server.launch()