9
9
Northwestern University, Evanston, IL.
10
10
11
11
TODO: Implement grass
12
-
13
12
'''
14
13
15
-
16
14
import random
17
15
18
16
from mesa import Model , Agent
@@ -29,18 +27,43 @@ class WolfSheepPredation(Model):
29
27
initial_sheep = 100
30
28
initial_wolves = 50
31
29
sheep_gain_from_food = 4
30
+
31
+ grass = False
32
+
32
33
wolf_gain_from_food = 20
33
34
sheep_reproduce = 0.04
34
35
wolf_reproduce = 0.05
35
36
36
37
height = 20
37
38
width = 20
38
39
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 ):
40
44
'''
41
45
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.
42
55
'''
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
44
67
45
68
self .schedule = Random_Activation (self )
46
69
self .grid = MultiGrid (self .height , self .width , torus = True )
@@ -118,13 +141,4 @@ def step(self, model):
118
141
cub = Wolf (self .grid , self .x , self .y , self .moore , self .energy / 2 )
119
142
self .energy = self .energy / 2
120
143
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