diff --git a/model.py b/model.py index c2043f0..677f00e 100644 --- a/model.py +++ b/model.py @@ -1,7 +1,7 @@ from mesa import Model, Agent from agent import Player from mesa.time import RandomActivation -from mesa.space import SingleGrid +from mesa.space import MultiGrid #from mesa.datacollection import DataCollector import random @@ -14,17 +14,23 @@ boxes_number = 5 class GameMap(Model): def __init__(self, x, y, boxes_number): - self.grid = SingleGrid(x, y, False) + self.grid = MultiGrid(x, y, False) self.schedule = RandomActivation(self) # agenci losowo po kolei wykonują swoje akcje # to jest potrzebne przy założeniu, że potwory chodzą? self.boxes_number = boxes_number + player = Player(1, self) + x = self.random.randrange(self.grid.width) + y = self.random.randrange(self.grid.height) + self.grid.place_agent(player, (x, y)) for i in range(self.boxes_number): box = Box(i, self) self.schedule.add(box) x = self.random.randrange(self.grid.width) y = self.random.randrange(self.grid.height) - self.grid.place_agent(box, (x, y)) - player = Player(i, self) + try: + self.grid.place_agent(box, (x, y)) + except: + pass # self.datacollector=DataCollector #informacje o stanie planszy, pozycja agenta @@ -41,6 +47,7 @@ class Box(Agent): # self.y_coor = random.randrange(1, y + 1) self.closed = True self.content = 'unknown' + self.isBox=True def open(self): self.closed = False diff --git a/server.py b/server.py index 072b68c..b3673e3 100644 --- a/server.py +++ b/server.py @@ -3,15 +3,18 @@ from mesa.visualization.modules import CanvasGrid from mesa.visualization.ModularVisualization import ModularServer -def box_representation(box): +def player_representation(agent): portrayal = {"Shape": "circle", "Filled": "true", "Layer": 0, "Color": "red", "r": 0.5} + if agent.isBox: + portrayal["Color"] = "grey" + portrayal["Layer"] = 1 return portrayal -grid = CanvasGrid(box_representation, 10, 10, 500, 500) +grid = CanvasGrid(player_representation, 10, 10, 500, 500) server = ModularServer(GameMap, [grid], "Map",