diff --git a/examples/wolf_sheep/wolf_sheep/model.py b/examples/wolf_sheep/wolf_sheep/model.py index 59f1835c..12db261a 100644 --- a/examples/wolf_sheep/wolf_sheep/model.py +++ b/examples/wolf_sheep/wolf_sheep/model.py @@ -79,15 +79,16 @@ def __init__( self.sheep_gain_from_food = sheep_gain_from_food self.grid = mesa.space.MultiGrid(self.width, self.height, torus=True) - self.datacollector = mesa.DataCollector( - { - "Wolves": lambda m: len(m.get_agents_of_type(Wolf)), - "Sheep": lambda m: len(m.get_agents_of_type(Sheep)), - "Grass": lambda m: len( - m.get_agents_of_type(GrassPatch).select(lambda a: a.fully_grown) - ), - } - ) + + collectors = { + "Wolves": lambda m: len(m.get_agents_of_type(Wolf)), + "Sheep": lambda m: len(m.get_agents_of_type(Sheep)), + } + + if grass: + collectors["Grass"] = lambda m: len(m.get_agents_of_type(GrassPatch)) + + self.datacollector = mesa.DataCollector(collectors) # Create sheep: for i in range(self.initial_sheep):