17
5
A mad scientist has just created a new species of bacterium! He has decided to name it Noblus Gentlemanus, after observing its behaviour. However, his bacteria have ran out of food, and have declared war, as they are able to harvest other bacterium's corpses for enough food to create copies of themselves. There are a number of different subspecies of this bacterium, who have different strategies in playing Prisoner's Dilemma, their favourite game. There are five bacteria from each different subspecies. In Prisoner's Dilemma, each of the two players simultaneously chooses either defect or cooperate. If one player chooses cooperate and the other chooses default, the defaulter gets 2 points, and the cooperator loses 3 points. If both player choose cooperate, both players get one 1 point. If both players choose default, both players lose 1 point.
Being Noble Gentlemen, the bacteria have decided to fight this war by playing 200 round long games of Iterated Prisoner's Dilemma. The loser of each duel will commit suicide, allowing the victor to clone itself. In the event of a tie, both bacteria will remain alive, but neither will be able to clone itself. In addition, all bacteria from a match carry over 10% of their points to the next match. A clone carries over the points of the bacterium it was cloned by. Also, there is a one in ten chance each turn that one bacterium will mutate into another subspecies, with 0 bonus points (if I receive complaints about the randomness of this, I can remove it). After the bacteria have played a number of these duels equal to the number of subspecies of bacteria times ten, the mad scientist accidentally drops the petri dish the bacteria reside in, and all of the bacteria acquire new sources of food, ending their duels. This is different from an ordinary iterated prisoner's dilemma contest, as it involves 1v1 duels with carryover points, rather than simply attempting to get the most points overall. This makes a big difference in how effective a given strategy is.
Each bacterium will receive input at the beginning of its turn in the format: (turn number, current points, enemies points, your previous moves [in a string, using the character "c" for cooperate, and the character "d" for defect], enemies previous moves [in the same format]).
Here are four sample strategies that will be entered. I actually think that Defector might win, even though it is extremely simple.
Tit for Tat
def titfortatfunc(counter, mypoints, enpoints, mylist, enlist):
if counter==0 or enlist[counter-1] == "c":
return "c"
else:
return "d"
RandomPick
from random import choice
def randompickfunc(counter, mypoints, enpoints, mylist, enlist):
if counter == 199:
return "d"
else:
return choice(["d", "c"])
Cooperator
def cooperatorfunc(counter, mypoints, enpoints, mylist, enlist):
return "c"
Defector
def defectorfunc(counter, mypoints, enpoints, mylist, enlist):
return "d"
All submissions must be in the form of a Python 2.7 function, with the name being the name of the submission with no spaces, with func
on the end. If someone would like to submit an answer in a different language, please enter it in pseudo-code, for me to convert to Python in an edit to your answer once I have time, or give me instructions on interfacing your language with my controller which is found below set up for all submissions as of June 4.
from titfortat import titfortatfunc
from randompick import randompickfunc
from cooperator import cooperatorfunc
from defector import defectorfunc
from luckytitfortat import luckytitfortatfunc
from randomtitfortat import randomtitfortatfunc
from remorsefulaggressor import remorsefulaggressorfunc
from everyother import everyotherfunc
from niceguy import niceguyfunc
from titfortatbackstab import titfortatbackstabfunc
from gentleDefector import gentleDefectorfunc
from anticapitalist import anticapitalistfunc
from grimtrigger import grimtriggerfunc
from bizzaro import bizzarofunc
from neoanticapitalist import neoanticapitalistfunc
from bittertat import bittertatfunc
from teamer import teamerfunc
from copyfirst import copyfirstfunc
from exploitivetat import exploitativetatfunc
from defectorv2 import defectorv2func
from crazytat import crazytatfunc
from randomchoicev2 import randomchoicev2func
from twotitsforatat import twotitsforatatfunc
from threetitsforatat import threetitsforatatfunc
from fourtitsforatat import fourtitsforatatfunc
from fivetitsforatat import fivetitsforatatfunc
from sixtitsforatat import sixtitsforatatfunc
from tentitsforatat import tentitsforatatfunc
from theelephant import theelephantfunc
from xbittertat import xbittertatfunc
from fifteentitsforatat import fifteentitsfortatfunc
from twentytitsforatat import twentytitsforatatfunc
from fox import foxfunc
from onehundredfortysixtitsforatat import onehundredfourtysixtitsforatatfunc
from gameofthrones import gameofthronesfunc
from boy import boyfunc
from grimace import grimacefunc
from fiftytitsforatat import fiftytitsfortatfunc
from soreloser import soreloserfunc
from everyotherd import everyotherdfunc
from fiftythreetitsfortat import fiftythreetitsfortatfunc
from twentyfivetitsfortat import twentyfivetitsfortatfunc
from handshake import handshakefunc
from anty import antyfunc
from fiftyfourtitsforatat import fiftyfourtitsfortatfunc
from kindatitsfortat import kindatitsfortatfunc
import random
players = 38
rounds = players*10
def runcode(num, points1, points2, history1, history2, cell):
ans = ""
if cell == 0:
ans = titfortatfunc(num, points1, points2, history1, history2)
elif cell == 1:
ans = randompickfunc(num, points1, points2, history1, history2)
elif cell == 2:
ans = cooperatorfunc(num, points1, points2, history1, history2)
elif cell == 3:
ans = defectorfunc(num, points1, points2, history1, history2)
elif cell == 4:
ans = luckytitfortatfunc(num, points1, points2, history1, history2)
elif cell == 5:
ans = randomtitfortatfunc(num, points1, points2, history1, history2)
elif cell == 6:
ans = remorsefulaggressorfunc(num, points1, points2, history1, history2)
elif cell == 7:
ans = everyotherfunc(num, points1, points2, history1, history2)
elif cell == 8:
ans = niceguyfunc(num, points1, points2, history1, history2)
elif cell == 9:
ans = titfortatbackstabfunc(num, points1, points2, history1, history2)
elif cell == 10:
ans = gentleDefectorfunc(num, points1, points2, history1, history2)
elif cell == 11:
ans = anticapitalistfunc(num, points1, points2, history1, history2)
elif cell == 12:
ans = grimtriggerfunc(num, points1, points2, history1, history2)
elif cell == 13:
ans = bizzarofunc(num, points1, points2, history1, history2)
elif cell == 14:
ans = neoanticapitalistfunc(num, points1, points2, history1, history2)
elif cell == 15:
ans = tentitsforatatfunc(num, points1, points2, history1, history2)
elif cell == 16:
ans = bittertatfunc(num, points1, points2, history1, history2)
elif cell == 17:
ans = copyfirstfunc(num, points1, points2, history1, history2)
elif cell == 18:
ans = exploitativetatfunc(num, points1, points2, history1, history2)
elif cell == 19:
ans = sixtitsforatatfunc(num, points1, points2, history1, history2)
elif cell == 20:
ans = fifteentitsfortatfunc(num, points1, points2, history1, history2)
elif cell == 21:
ans = fivetitsforatatfunc(num, points1, points2, history1, history2)
elif cell == 22:
ans = twentytitsforatatfunc(num, points1, points2, history1, history2)
elif cell == 23:
ans = threetitsforatatfunc(num, points1, points2, history1, history2)
elif cell == 24:
ans = fiftyfourtitsfortatfunc(num, points1, points2, history1, history2)
elif cell == 25:
ans = theelephantfunc(num, points1, points2, history1, history2)
elif cell == 26:
ans = xbittertatfunc(num, points1, points2, history1, history2)
elif cell == 27:
ans = foxfunc(num, points1, points2, history1, history2)
elif cell == 28:
ans = gameofthronesfunc(num, points1, points2, history1, history2)
elif cell == 29:
ans = boyfunc(num, points1, points2, history1, history2)
elif cell == 30:
ans = grimacefunc(num, points1, points2, history1, history2)
elif cell == 31:
ans = soreloserfunc(num, points1, points2, history1, history2)
elif cell == 32:
ans = everyotherdfunc(num, points1, points2, history1, history2)
elif cell == 33:
ans = twentyfivetitsfortatfunc(num, points1, points2, history1, history2)
elif cell == 34:
ans = fiftythreetitsfortatfunc(num, points1, points2, history1, history2)
elif cell == 35:
ans = handshakefunc(num, points1, points2, history1, history2)
elif cell == 36:
ans = antyfunc(num, points1, points2, history1, history2)
elif cell == 37:
ans = kindatitsfortatfunc(num, points1, points2, history1, history2)
return ans
def fight(l1,l2):
num1,num2=l1[0],l2[0]
points1,points2=l1[1],l2[1]
history1 = ""
history2 = ""
for num in range(200):
p1 = runcode(num, points1, points2, history1, history2, num1)
p2 = runcode(num, points2, points1, history2, history1, num2)
history1+=p1
history2+=p2
if p1 == "c" and p2 == "c":
points1 += 1
points2 += 1
elif p1 == "c" and p2 == "d":
points1 -= 3
points2 += 2
elif p1 == "d" and p2 == "c":
points1 += 2
points2 -= 3
elif p1 == "d" and p2 == "d":
points1 -= 1
points2 -= 1
if points1 > points2:
return [l1[0], points1/10], [l1[0], points1/10]
elif points1 < points2:
return [l2[0], points2/10], [l2[0], points2/10]
else:
return [l1[0], points1/10], [l2[0], points2/10]
def rounddoer(bots):
bots2=[]
for x in range(len(bots)):
if x%2==0:
out1, out2 = fight(bots[x], bots[x-1])
bots2.append(out1)
bots2.append(out2)
return bots2
def gamedoer():
bots=[[0,0],[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],[15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],[22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],[29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],[36,0],[37,0],[0,0],[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],[15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],[22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],[29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],[36,0],[37,0],[0,0],[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],[15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],[22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],[29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],[36,0],[37,0],[0,0],[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],[15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],[22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],[29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],[36,0],[37,0],[0,0],[1,0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0],[11,0],[12,0],[13,0],[14,0],[15,0],[16,0],[17,0],[18,0],[19,0],[20,0],[21,0],[22,0],[23,0],[24,0],[25,0],[26,0],[27,0],[28,0],[29,0],[30,0],[31,0],[32,0],[33,0],[34,0],[35,0],[36,0],[37,0]]
random.shuffle(bots)
counter=0
while counter < rounds:
counter += 1
bots = rounddoer(bots)
if random.randint(0,10) == 9:
bots[random.randint(0, players*5)-1] = [random.randint(0, players-1), 0]
random.shuffle(bots)
## for item in bots:
## print str(item[0]) + " with " + str(item[1]) + " bonus points."
return bots
a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,mycounter=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
while mycounter < 1000:
mycounter += 1
bots = gamedoer()
print "Game: " + str(mycounter)
for item in bots:
if item[0]==0:
a0 += 1
if item[0]==1:
a1 += 1
if item[0]==2:
a2 += 1
if item[0]==3:
a3 += 1
if item[0]==4:
a4 += 1
if item[0]==5:
a5 += 1
if item[0]==6:
a6 += 1
if item[0]==7:
a7 += 1
if item[0]==8:
a8 += 1
if item[0]==9:
a9 += 1
if item[0]==10:
a10 += 1
if item[0]==11:
a11 += 1
if item[0]==12:
a12 += 1
if item[0]==13:
a13 += 1
if item[0]==14:
a14+=1
if item[0]==15:
a15+=1
if item[0]==16:
a16+=1
if item[0]==17:
a17+=1
if item[0]==18:
a18 += 1
if item[0]==19:
a19+=1
if item[0]==20:
a20+=1
if item[0]==21:
a21+=1
if item[0]==22:
a22+=1
if item[0]==23:
a23+=1
if item[0]==24:
a24+=1
if item[0]==25:
a25+=1
if item[0]==26:
a26+=1
if item[0]==27:
a27+=1
if item[0]==28:
a28+=1
if item[0]==29:
a29+=1
if item[0]==30:
a30+=1
if item[0]==31:
a31+=1
if item[0]==32:
a32+=1
if item[0]==33:
a33+=1
if item[0]==34:
This Contest is now Finished
If you would like to add an answer, I'll see if I can get around to adding a post-challenge scoreboard under the one for the original contestants. I'll be adding that one as soon as the testing program finishes (probably 2-3 more days).
FINAL SCORES!!!!!
Tit for Tat: 18
Random Pick: 28
Cooperator: 19
Defector: 24
Lucky Tit for Tat: 23
Random Tit for Tat: 23
Remorseful Aggressor: 22
Every Other C: 23
Nice Guy: 18
Tit for Tat Backstab: 15
Gentle Defector: 22
Anticapitalist: 27
Grim Trigger: 19
Bizzaro: 21
NeoAnticapitalist: 24
Ten Tits for a Tat: 240
Bitter Tat: 12
Copy First: 30
Exploitative Tat: 19
Six Tits for a Tat: 16
Thirty Tits for Tat: 4129
Five Tits for a Tat: 22
Forty Tits for a Tat: 1972
Three Tits for a Tat: 22
Fifty Four Tits for a Tat: 25805
The Elephant: 31
Extra Bitter Tat: 28
Fox: 35
Game of Thrones: 11297
The Boy: 31
Grimace: 26
Sore Loser: 39
Every Other D: 18
Twenty Five Tits for a Tat: 2399
Fifty Three Tits for a Tat: 5487
Handshake: 28
Anty: 26
Kinda Tits for Tat: 20
Prudent Defector: 154539
Bizzarro Trigger: 25
Young Mathematician: 21
Older Mathematician: 16
Perfect Gentleman: 1953341
So, it appears that Perfect Gentleman is the winner. Congratulations to Draco18, who definitely deserves his green checkmark.
Comments are not for extended discussion; this conversation has been moved to chat.
– Dennis – 2017-05-31T22:37:21.0031NOTE: IF YOU ARE EDITING YOUR PROGRAM, PLEASE GIVE ME A COMMENT SO I NOTICE, OR IT MAY NOT BE PUT ON THE SCOREBOARD FOR A WHILE!!!!!!!!!!!!!!!!!!!!!!! – Gryphon – 2017-06-01T00:52:53.757
Yikes! I just realised how many imports that is. – Gryphon – 2017-06-04T20:56:59.607
1Hey Gryphon, you working on those final rankings? ;) – Draco18s no longer trusts SE – 2017-07-09T15:07:24.147
Sorry, I forgot about this. Give me a bit to run it. – Gryphon – 2017-07-09T15:48:28.780
OK, running as we speak. This is going to take a LONG time, so it probably won't be up for a couple days. – Gryphon – 2017-07-09T18:51:52.000
Looks like PG is just going to miss the 2 million mark. – Gryphon – 2017-07-10T01:28:20.030
@Draco18s, I'm at round 2050, and PG just broke 400,000. Should be able to post in 3-4 days. – Gryphon – 2017-07-11T00:25:36.057
@Gryphon oh wow, taking a while! Good to know. – Draco18s no longer trusts SE – 2017-07-11T01:39:24.377
Sorry, but 10,000 games is a lot to run. Especially when your computer is, well, my computer. – Gryphon – 2017-07-11T01:47:56.493
Are you going to post the final results? – MegaTom – 2017-07-11T20:15:25.623
As soon as they're done. I started 2 days ago, and I'm on round 3,380 out of 10,000 – Gryphon – 2017-07-11T20:17:50.423
My computer's slow. – Gryphon – 2017-07-11T20:18:15.143
OK, so I've got bad news, and worse news. – Gryphon – 2017-07-16T15:06:14.057
The bad news is that windows updated, stopping my program, so I have to run it again. – Gryphon – 2017-07-16T15:13:11.867
The worse news, is that I'll be gone for the next week, so I won't have access to the program. Unfortunately, it looks like you'll have to wait until next Sunday or Monday for the results. I can confirm, however, that Perfect Gentleman is almost definitely the winner. – Gryphon – 2017-07-16T15:14:26.463
No worries, Gryphon. :) – Draco18s no longer trusts SE – 2017-07-23T19:03:25.937