99 Northwestern University, Evanston, IL.
1010
1111TODO: Implement grass
12-
1312'''
1413
15-
1614import random
1715
1816from mesa import Model , Agent
@@ -29,18 +27,43 @@ class WolfSheepPredation(Model):
2927 initial_sheep = 100
3028 initial_wolves = 50
3129 sheep_gain_from_food = 4
30+
31+ grass = False
32+
3233 wolf_gain_from_food = 20
3334 sheep_reproduce = 0.04
3435 wolf_reproduce = 0.05
3536
3637 height = 20
3738 width = 20
3839
39- def __init__ (self ):
40+ def __init__ (self , height = 20 , width = 20 ,
41+ initial_sheep = 100 , initial_wolves = 50 , sheep_reproduce = 0.04 ,
42+ wolf_reproduce = 0.05 , wolf_gain_from_food = 20 ,
43+ grass = False , sheep_gain_from_food = 4 ):
4044 '''
4145 Create a new Wolf-Sheep model with the given parameters.
46+
47+ Args:
48+ initial_sheep: Number of sheep to start with
49+ initial_wolves: Number of wolves to start with
50+ sheep_reproduce: Probability of each sheep reproducing each step
51+ wolf_reproduce: Probability of each wolf reproducing each step
52+ wolf_gain_from_food: Energy a wolf gains from eating a sheep
53+ grass: Whether to have the sheep eat grass for energy
54+ sheep_gain_from_food: Energy sheep gain from grass, if enabled.
4255 '''
43- #TODO: Accept all other parameters
56+
57+ # Set parameters
58+ self .height = height
59+ self .width = width
60+ self .initial_sheep = initial_sheep
61+ self .initial_wolves = initial_wolves
62+ self .sheep_reproduce = sheep_reproduce
63+ self .wolf_reproduce = wolf_reproduce
64+ self .wolf_gain_from_food = wolf_gain_from_food
65+ self .grass = grass
66+ self .sheep_gain_from_food = sheep_gain_from_food
4467
4568 self .schedule = Random_Activation (self )
4669 self .grid = MultiGrid (self .height , self .width , torus = True )
@@ -118,13 +141,4 @@ def step(self, model):
118141 cub = Wolf (self .grid , self .x , self .y , self .moore , self .energy / 2 )
119142 self .energy = self .energy / 2
120143 model .grid [self .y ][self .x ].add (cub )
121- model .schedule .add (cub )
122-
123-
124-
125-
126-
127-
128-
129-
130-
144+ model .schedule .add (cub )
0 commit comments