Skip to content

Commit a68ae49

Browse files
committed
Adding parameters and fixing style issues
1 parent b13748e commit a68ae49

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

examples/WolfSheep/WolfSheep.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
Northwestern University, Evanston, IL.
1010
1111
TODO: Implement grass
12-
1312
'''
1413

15-
1614
import random
1715

1816
from 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)

examples/WolfSheep/WolfSheepVisualization.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def draw_cell(cell):
2424
return " "
2525
if len([obj for obj in cell if isinstance(obj, Sheep)]) == len(cell):
2626
return "S"
27-
elif len([obj for obj in cell if isinstance(obj, Wolf)]) == len(cell):
27+
if len([obj for obj in cell if isinstance(obj, Wolf)]) == len(cell):
2828
return "W"
2929
else:
30-
return "X"
31-
30+
return "X"

0 commit comments

Comments
 (0)