diff --git a/examples/hex_ant/app.py b/examples/hex_ant/app.py index 952f391f9..05cdef0c3 100644 --- a/examples/hex_ant/app.py +++ b/examples/hex_ant/app.py @@ -3,8 +3,12 @@ from mesa.visualization import SolaraViz, make_space_component from mesa.visualization.components import PropertyLayerStyle -from .agent import AntState -from .model import AntForaging +try: + from .agent import AntState + from .model import AntForaging +except ImportError: + from agent import AntState + from model import AntForaging plt.rcParams["figure.figsize"] = (10, 10) diff --git a/examples/hex_ant/model.py b/examples/hex_ant/model.py index 96998d22b..8ec0319f3 100644 --- a/examples/hex_ant/model.py +++ b/examples/hex_ant/model.py @@ -1,7 +1,10 @@ import mesa from mesa.discrete_space import HexGrid -from .agent import Ant +try: + from .agent import Ant +except ImportError: + from agent import Ant class AntForaging(mesa.Model): @@ -57,9 +60,9 @@ def _init_environment(self): # Create the Nest in the center center = (self.grid.width // 2, self.grid.height // 2) # Spike the 'home' pheromone at the nest so ants can find it initially - self.grid.pheromone_home[center] = 1.0 + self.grid.pheromone_home.data[center] = 1.0 # Mark the home location - self.grid.home[center] = 1 + self.grid.home.data[center] = 1 # Scatter some Food Sources # Create 3 big clusters of food @@ -101,7 +104,7 @@ def _update_pheromone_layer(self, layer_name): """ Apply evaporation to a pheromone layer. """ - np_layer = self.grid.property_layers[layer_name] + np_layer = getattr(self.grid, layer_name).data np_layer *= 1.0 - self.evaporation_rate # Clamp to 0 to prevent negative values diff --git a/rl/wolf_sheep/agents.py b/rl/wolf_sheep/agents.py index 1bb79db5d..0d5d2325e 100644 --- a/rl/wolf_sheep/agents.py +++ b/rl/wolf_sheep/agents.py @@ -51,7 +51,7 @@ def step(self): self.energy -= 1 # If there are sheep present, eat one - x, y = self.pos + _x, _y = self.pos this_cell = self.model.grid.get_cell_list_contents([self.pos]) sheep = [obj for obj in this_cell if isinstance(obj, Sheep)] if len(sheep) > 0: