So the other day I made this simple code that simulates what’s going on in this video: Simulating the Evolution of Aggression.
Code:
import random as yMIDoingTisToMe
dNum=int(input("eDove"))
hNum=int(input("eHawk"))
fPlNum=int(input("eFPl"))
bLst=[]
fPlLst=[]
fPlLst2=fPlLst
for i in range(dNum):
bLst.append(1)
for i in range(hNum):
bLst.append(2)
for i in range(fPlNum):
fPlLst.append(0)
fPlLst2=fPlLst
for a in range(1,1000):
delBLst=[]
fPlLst=[]
for i in range(fPlNum):
fPlLst.append(0)
fPlLst2=fPlLst.copy()
yMIDoingTisToMe.shuffle(bLst)
for blob in bLst: #razvrščanje
isin=fPlLst.count(0)<1 or fPlLst2.count(0)<1
if isin:
delBLst.append(blob)
while not isin:
sTo=yMIDoingTisToMe.randint(0,fPlNum-1)
if fPlLst[sTo]==0:
fPlLst[sTo]=blob
isin=True
elif fPlLst2[sTo]==0:
fPlLst2[sTo]=blob
isin=True
for i in range(fPlNum): #razmnoževanje
if (fPlLst[i]==1 and fPlLst2[i]==1) or (fPlLst[i]==0 and fPlLst2[i]==0):
pass
elif fPlLst[i]==1 and fPlLst2[i]==0:
bLst.append(1)
elif fPlLst[i]==2 and fPlLst2[i]==0:
bLst.append(2)
elif (fPlLst[i]==2 and fPlLst2[i]==1) or (fPlLst[i]==1 and fPlLst2[i]==2):
if yMIDoingTisToMe.randint(0,1)==1:
bLst.append(2)
if yMIDoingTisToMe.randint(0,1)==0:
delBLst.append(1)
elif fPlLst[i]==2 and fPlLst2[i]==2:
delBLst.append(2)
delBLst.append(2)
for i in delBLst:
bLst.pop(i)
print(f"doves:{bLst.count(1)} hawks:{bLst.count(2)} gen:{a}")
and it didn’t work as expected.
Try it for yourself, see and please ansawer.
I only stared in the code for 2 hours and didn’t manage anything.
New contributor
AlphaOmega is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1