I have two lists, positions_rabbits_x (with all the x coordinates) and positions_rabbits_y (with all y coords). After my program runs 200 sec.my "rabbits" are reproducing, however when I call this function my program crashes. (it doesn't print an error, just overloads because it adds too many "rabbits" my computer so it doesn't respond anymore) Many thanks!!
def reproducing_rabbits():
global positions_rabbits_x, positions_rabbits_y
global rabbits_angles
angle = 2 * math.pi * random.random()
index = 0
for rabx in range(len(positions_rabbits_x)-1,-1,-1):
for rabx2 in range(len(positions_rabbits_y)):
distance = math.sqrt((positions_rabbits_x[rabx] - positions_rabbits_x[rabx2])**2 + (positions_rabbits_y[rabx] - positions_rabbits_y[rabx2])**2)
if distance < 1:
index += 1
if index == 1:
positions_rabbits_x.append(random.randint(1, 100))
positions_rabbits_y.append(random.randint(1,100))
rabbits_angles.append(angle)
index = 0
else:
pass
return