diff --git a/mesa/examples/advanced/wolf_sheep/agents.py b/mesa/examples/advanced/wolf_sheep/agents.py index e3f308aa479..e262996fcff 100644 --- a/mesa/examples/advanced/wolf_sheep/agents.py +++ b/mesa/examples/advanced/wolf_sheep/agents.py @@ -4,7 +4,9 @@ class Animal(CellAgent): """The base animal class.""" - def __init__(self, model, energy, p_reproduce, energy_from_food, cell): + def __init__( + self, model, energy=8, p_reproduce=0.04, energy_from_food=4, cell=None + ): """Initialize an animal. Args: diff --git a/mesa/examples/advanced/wolf_sheep/model.py b/mesa/examples/advanced/wolf_sheep/model.py index cc6ec6acc9f..73b9c26a833 100644 --- a/mesa/examples/advanced/wolf_sheep/model.py +++ b/mesa/examples/advanced/wolf_sheep/model.py @@ -90,22 +90,23 @@ def __init__( self.datacollector = DataCollector(model_reporters) # Create sheep: - for _ in range(initial_sheep): - pos = ( - self.random.randrange(width), - self.random.randrange(height), - ) - energy = self.random.randrange(2 * sheep_gain_from_food) - Sheep(self, energy, sheep_reproduce, sheep_gain_from_food, self.grid[pos]) - - # Create wolves - for _ in range(initial_wolves): - pos = ( - self.random.randrange(width), - self.random.randrange(height), - ) - energy = self.random.randrange(2 * wolf_gain_from_food) - Wolf(self, energy, wolf_reproduce, wolf_gain_from_food, self.grid[pos]) + Sheep.create_agents( + self, + initial_sheep, + energy=self.rng.random((initial_sheep,)) * 2 * sheep_gain_from_food, + p_reproduce=sheep_reproduce, + energy_from_food=sheep_gain_from_food, + cell=self.random.choices(self.grid.all_cells.cells, k=initial_sheep), + ) + # Create Wolves: + Wolf.create_agents( + self, + initial_wolves, + energy=self.rng.random((initial_wolves,)) * 2 * wolf_gain_from_food, + p_reproduce=wolf_reproduce, + energy_from_food=wolf_gain_from_food, + cell=self.random.choices(self.grid.all_cells.cells, k=initial_wolves), + ) # Create grass patches if enabled if grass: