Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions episodes/files/pred-prey/predprey.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ def avoid_predators(self, predator_list):

# Add a steering factor away from each predator. Strength increases with closeness.
for predator in predator_list:
# Fetch location of predator
predator_x = self.x;
predator_y = self.y;

# Check if the two predators are within interaction radius
# Check if predator and prey are within interaction radius
dx = self.x - predator.x
dy = self.y - predator.y
distance = math.sqrt(dx * dx + dy * dy)
Expand Down Expand Up @@ -159,6 +155,7 @@ def reproduce(self):
child.vx = np.random.uniform() * 2 - 1
child.vy = np.random.uniform() * 2 - 1
child.life = self.life
return child


class Predator:
Expand Down Expand Up @@ -304,7 +301,7 @@ def eaten(self, prey_list):

class Model:

def __init__(self, steps = 250):
def __init__(self, steps = 50):
self.steps = steps
self.num_prey = 200
self.num_predators = 50
Expand Down Expand Up @@ -373,7 +370,7 @@ def _step(self):
c = p.reproduce()
if c:
children.append(c)
self.predators.extend(children)
self.prey.extend(children)
children = []
for p in self.predators:
c = p.reproduce()
Expand Down
Loading