pudlles implementation without weights
This commit is contained in:
parent
f6a07386a8
commit
7324fc47d9
12
GameModel.py
12
GameModel.py
@ -17,7 +17,7 @@ from util.PathDefinitions import GridLocation, GridWithWeights
|
|||||||
|
|
||||||
class GameModel(Model):
|
class GameModel(Model):
|
||||||
|
|
||||||
def __init__(self, width, height, graph: GridWithWeights):
|
def __init__(self, width, height, graph: GridWithWeights, graph2: GridWithWeights):
|
||||||
# self.num_agents = 5
|
# self.num_agents = 5
|
||||||
self.running = True
|
self.running = True
|
||||||
self.grid = MultiGrid(height, width, True)
|
self.grid = MultiGrid(height, width, True)
|
||||||
@ -33,7 +33,8 @@ class GameModel(Model):
|
|||||||
self.game_constants = GameConstants(
|
self.game_constants = GameConstants(
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
graph.walls
|
graph.walls,
|
||||||
|
graph2.puddles
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add the agent to a random grid cell
|
# Add the agent to a random grid cell
|
||||||
@ -53,6 +54,7 @@ class GameModel(Model):
|
|||||||
|
|
||||||
self.place_patch_agents()
|
self.place_patch_agents()
|
||||||
self.place_walls_agents(graph.walls)
|
self.place_walls_agents(graph.walls)
|
||||||
|
self.place_puddles(graph2.puddles)
|
||||||
|
|
||||||
actions = pathFinder.getActionList()
|
actions = pathFinder.getActionList()
|
||||||
print("PATHFINDING")
|
print("PATHFINDING")
|
||||||
@ -81,6 +83,12 @@ class GameModel(Model):
|
|||||||
self.agents.append(agent)
|
self.agents.append(agent)
|
||||||
self.grid.place_agent(agent, w)
|
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):
|
def step(self):
|
||||||
self.schedule.step()
|
self.schedule.step()
|
||||||
|
|
||||||
|
@ -6,3 +6,4 @@ class PatchType(enum.Enum):
|
|||||||
pickUp = 2
|
pickUp = 2
|
||||||
item = 3
|
item = 3
|
||||||
wall = 4
|
wall = 4
|
||||||
|
diffTerrain = 5
|
||||||
|
@ -12,7 +12,8 @@ class GameConstants:
|
|||||||
# delivery_pos: GridLocation,
|
# delivery_pos: GridLocation,
|
||||||
# order_pos: GridLocation,
|
# order_pos: GridLocation,
|
||||||
# special_positions: Dict[ItemType, GridLocation],
|
# special_positions: Dict[ItemType, GridLocation],
|
||||||
walls: [GridLocation]
|
walls: [GridLocation],
|
||||||
|
puddles: [GridLocation]
|
||||||
):
|
):
|
||||||
self.grid_width = grid_width
|
self.grid_width = grid_width
|
||||||
self.grid_height = grid_height
|
self.grid_height = grid_height
|
||||||
@ -20,3 +21,4 @@ class GameConstants:
|
|||||||
# self.order_pos = order_pos
|
# self.order_pos = order_pos
|
||||||
# self.special_positions = special_positions
|
# self.special_positions = special_positions
|
||||||
self.walls = walls
|
self.walls = walls
|
||||||
|
self.puddles = puddles
|
||||||
|
BIN
img/puddle.png
Normal file
BIN
img/puddle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
7
main.py
7
main.py
@ -38,6 +38,8 @@ def agent_portrayal(agent):
|
|||||||
portrayal = {"Shape": "img/truck.png", "scale": 1.0, "Layer": 0}
|
portrayal = {"Shape": "img/truck.png", "scale": 1.0, "Layer": 0}
|
||||||
elif agent.patch_type == PatchType.pickUp:
|
elif agent.patch_type == PatchType.pickUp:
|
||||||
portrayal = {"Shape": "img/okB00mer.png", "scale": 1.0, "Layer": 0}
|
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:
|
else:
|
||||||
color = colors[random.randrange(13) + 3]
|
color = colors[random.randrange(13) + 3]
|
||||||
portrayal = {"Shape": "rect",
|
portrayal = {"Shape": "rect",
|
||||||
@ -58,12 +60,15 @@ if __name__ == '__main__':
|
|||||||
diagram4 = GridWithWeights(gridWidth, gridHeight)
|
diagram4 = GridWithWeights(gridWidth, gridHeight)
|
||||||
diagram4.walls = [(6, 5), (6, 6), (6, 7), (6, 8), (2, 3), (2, 4)]
|
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)
|
grid = CanvasGrid(agent_portrayal, gridWidth, gridHeight, scale * gridWidth, scale * gridHeight)
|
||||||
|
|
||||||
server = ModularServer(GameModel,
|
server = ModularServer(GameModel,
|
||||||
[grid],
|
[grid],
|
||||||
"Automatyczny Wózek Widłowy",
|
"Automatyczny Wózek Widłowy",
|
||||||
{"width": gridHeight, "height": gridWidth, "graph": diagram4})
|
{"width": gridHeight, "height": gridWidth, "graph": diagram4, "graph2": diagram5},)
|
||||||
|
|
||||||
server.port = 8888
|
server.port = 8888
|
||||||
server.launch()
|
server.launch()
|
||||||
|
@ -13,6 +13,7 @@ class SquareGrid:
|
|||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.walls: List[GridLocation] = []
|
self.walls: List[GridLocation] = []
|
||||||
|
self.puddles: List[GridLocation] = []
|
||||||
|
|
||||||
def in_bounds(self, id: GridLocation) -> bool:
|
def in_bounds(self, id: GridLocation) -> bool:
|
||||||
(x, y) = id
|
(x, y) = id
|
||||||
|
Loading…
Reference in New Issue
Block a user