Noisy Iterated Prisoner's Dilemma
Tit-For-Whoops
Inspired by a strategy from ncase.me/trust
def tit_for_whoops(m, t, s):
if len(t) < 2:
return 'c'
else:
return 'd' if all([x == 'd' for x in t[-2:]]) else 'c'
Defects only if the other player has defected twice in a row, to prevent misunderstandings.
Change of Heart
def change_of_heart(m, t, s):
return 'c' if len(t) < 180 else 'd'
Has a change of heart partway through. Does surprisingly well.
Strategy Stealer
Inspired by enough, change_of_heart, and tit-for-whoops. Should be a little more forgiving. I tried to tweak the numbers for best results but they didn't want to change much.
def stealer(mine, theirs, state):
if len(mine) == 0:
state.append('c')
return 'c'
elif len(mine) > 250:
return "d"
elif state[0] == 't':
return 'd'
elif mine[-40:].count('d') > 10:
state[0] = 't'
return 'd'
elif theirs[-1] == 'd':
if state[0] == 'd':
state[0] = 'c'
return 'd'
else:
state[0] = 'd'
return 'c'
elif all([x == 'c' for x in theirs[-3:]]):
state[0] = 'c'
return 'c'
else:
return 'c'