Skip to content

Commit 2a6ba48

Browse files
committed
Prevent division by zero in PredPrey example
1 parent 40ef0d8 commit 2a6ba48

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

episodes/files/pred-prey/predprey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def flock(self, prey_list):
8484
group_centre_count += 1
8585

8686
# Avoidance behaviour
87-
if separation < SAME_SPECIES_AVOIDANCE_RADIUS:
87+
if separation < SAME_SPECIES_AVOIDANCE_RADIUS and separation > 0:
8888
# Was a check for separation > 0 in original - redundant?
8989
avoid_velocity_x += SAME_SPECIES_AVOIDANCE_RADIUS / separation * dx
9090
avoid_velocity_y += SAME_SPECIES_AVOIDANCE_RADIUS / separation * dy

0 commit comments

Comments
 (0)