The Iterated Prisoner’s Dilemma is a classic problem in game theory, and I decided to make a “competition” for it. (the winner gets nothing) Posting early because blystii guessed a number…
Rules
One submission per user. I won’t include second submissions.
Strategies must only use built-in Python features, plus the random module, and must not have any side effects.
Strategies may be at most 256 LLOC (Logical Lines of Code).
Strategies must terminate. You may use a while True or any other way to loop indefinitely, so long as it is guaranteed to terminate.
Strategy names must be unique. If they are not unique, the name of the submitter will be prepended.
The deadline for submissions is December 31st, 23:59 UTC. Results should be announced by January 2nd, who knows if I’ll remember.
Making a submission
Format for submitting
Name: your name here
# your code here
Example submission
Name: tit_for_tat
def tit_for_tat(ours, theirs):
return theirs[-1] if theirs else True
A strategy is really just a Python function taking a list of its own moves, and its opponent’s moves. Returning True means the strategy wishes to cooperate, returning False means it wishes to defect. Note that the lists of moves are not updated until both moves are made.
How winners will be decided
Temptation (T) is 5.
Reward (R) is 3.
Punishment (P) is 1.
Sucker (S) is 0.
This satisfies the two rules for the iterated prisoner’s dilemma:
T > R > P > S
2R > T + S
Visually, this means:
Payoff Matrix
You Cooperate
You Defect
They Cooperate
You get 3, they get 3
You get 5, they get 0
They Defect
They get 5, you get 0
You get 1, they get 1
The winner is whoever gets the most points across all matchups.
Strategies will be faced off against each other, round-robin style.
Notes
“Counter strategies”, those which exist soley to perform well against certain strategies, are strongly discouraged.
This top one is my actual submission, I just wanted to make some others for fun.
Name: majority_rule
def majority_rule(ours, theirs):
if ours:return theirs.count(True) > theirs.count(False)
return True
I remember seeing a game like this and I recall the optimal strategy (of the ones they tried), but this seems more fun and interesting.
Now for the ones I’m NOT submitting
Feel free to include these for the fun of it or not at all, I don’t care if I won’t win with them, I just think it’d be fun to see them compete.
Name: confused_mathematician
def confused_mathematician(ours, theirs):
n = len(ours)
for i in range(2, int(n**0.5) + 1):
if n % i == 0:return False
return True