File tree Expand file tree Collapse file tree 1 file changed +4
-7
lines changed
Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -51,11 +51,7 @@ def avoid_predators(self, predator_list):
5151
5252 # Add a steering factor away from each predator. Strength increases with closeness.
5353 for predator in predator_list :
54- # Fetch location of predator
55- predator_x = self .x ;
56- predator_y = self .y ;
57-
58- # Check if the two predators are within interaction radius
54+ # Check if predator and prey are within interaction radius
5955 dx = self .x - predator .x
6056 dy = self .y - predator .y
6157 distance = math .sqrt (dx * dx + dy * dy )
@@ -159,6 +155,7 @@ def reproduce(self):
159155 child .vx = np .random .uniform () * 2 - 1
160156 child .vy = np .random .uniform () * 2 - 1
161157 child .life = self .life
158+ return child
162159
163160
164161class Predator :
@@ -304,7 +301,7 @@ def eaten(self, prey_list):
304301
305302class Model :
306303
307- def __init__ (self , steps = 250 ):
304+ def __init__ (self , steps = 50 ):
308305 self .steps = steps
309306 self .num_prey = 200
310307 self .num_predators = 50
@@ -373,7 +370,7 @@ def _step(self):
373370 c = p .reproduce ()
374371 if c :
375372 children .append (c )
376- self .predators .extend (children )
373+ self .prey .extend (children )
377374 children = []
378375 for p in self .predators :
379376 c = p .reproduce ()
You can’t perform that action at this time.
0 commit comments