diff --git a/GameModel.py b/GameModel.py index 6f42f20..1630c8c 100644 --- a/GameModel.py +++ b/GameModel.py @@ -17,7 +17,7 @@ from util.PathDefinitions import GridLocation, GridWithWeights class GameModel(Model): - def __init__(self, width, height, graph: GridWithWeights): + def __init__(self, width, height, graph: GridWithWeights, graph2: GridWithWeights): # self.num_agents = 5 self.running = True self.grid = MultiGrid(height, width, True) @@ -33,7 +33,8 @@ class GameModel(Model): self.game_constants = GameConstants( width, height, - graph.walls + graph.walls, + graph2.puddles ) # Add the agent to a random grid cell @@ -53,6 +54,7 @@ class GameModel(Model): self.place_patch_agents() self.place_walls_agents(graph.walls) + self.place_puddles(graph2.puddles) actions = pathFinder.getActionList() print("PATHFINDING") @@ -81,6 +83,12 @@ class GameModel(Model): self.agents.append(agent) self.grid.place_agent(agent, w) + def place_puddles(self, puddles: List[GridLocation]): + for p in puddles: + agent = PatchAgent(self, PatchType.diffTerrain) + self.agents.append(agent) + self.grid.place_agent(agent, p) + def step(self): self.schedule.step() diff --git a/PatchType.py b/PatchType.py index 3b1bf71..283857a 100644 --- a/PatchType.py +++ b/PatchType.py @@ -6,3 +6,4 @@ class PatchType(enum.Enum): pickUp = 2 item = 3 wall = 4 + diffTerrain = 5 diff --git a/data/GameConstants.py b/data/GameConstants.py index c22f08f..a54b75e 100644 --- a/data/GameConstants.py +++ b/data/GameConstants.py @@ -12,7 +12,8 @@ class GameConstants: # delivery_pos: GridLocation, # order_pos: GridLocation, # special_positions: Dict[ItemType, GridLocation], - walls: [GridLocation] + walls: [GridLocation], + puddles: [GridLocation] ): self.grid_width = grid_width self.grid_height = grid_height @@ -20,3 +21,4 @@ class GameConstants: # self.order_pos = order_pos # self.special_positions = special_positions self.walls = walls + self.puddles = puddles diff --git a/img/puddle.png b/img/puddle.png new file mode 100644 index 0000000..b9a5484 Binary files /dev/null and b/img/puddle.png differ diff --git a/main.py b/main.py index 1c270db..1339552 100644 --- a/main.py +++ b/main.py @@ -38,6 +38,8 @@ def agent_portrayal(agent): portrayal = {"Shape": "img/truck.png", "scale": 1.0, "Layer": 0} elif agent.patch_type == PatchType.pickUp: portrayal = {"Shape": "img/okB00mer.png", "scale": 1.0, "Layer": 0} + elif agent.patch_type == PatchType.diffTerrain: + portrayal = {"Shape": "img/puddle.png", "scale": 1.0, "Layer": 0} else: color = colors[random.randrange(13) + 3] portrayal = {"Shape": "rect", @@ -58,12 +60,15 @@ if __name__ == '__main__': diagram4 = GridWithWeights(gridWidth, gridHeight) diagram4.walls = [(6, 5), (6, 6), (6, 7), (6, 8), (2, 3), (2, 4)] + diagram5 = GridWithWeights(gridWidth, gridHeight) + diagram5.puddles = [(2, 2), (2, 5)] + 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}) + {"width": gridHeight, "height": gridWidth, "graph": diagram4, "graph2": diagram5},) server.port = 8888 server.launch() diff --git a/util/PathDefinitions.py b/util/PathDefinitions.py index bf5c98b..99ae044 100644 --- a/util/PathDefinitions.py +++ b/util/PathDefinitions.py @@ -13,6 +13,7 @@ class SquareGrid: self.width = width self.height = height self.walls: List[GridLocation] = [] + self.puddles: List[GridLocation] = [] def in_bounds(self, id: GridLocation) -> bool: (x, y) = id