Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 37 ยท Projects and Practice

Project: An Axelrod Tournament

Build a round-robin prisoner's dilemma tournament in Python with eight strategies, add noise, run an evolutionary population, and learn what makes a strategy succeed.

In 1980 the political scientist Robert Axelrod invited experts to submit computer programs for a repeated prisoner's dilemma tournament. Every program played every other. The winner was the shortest entry, tit-for-tat. In this project you will rebuild the tournament, add noise (mistakes), and then let the population evolve by the replicator idea from the evolutionary chapter. You will use only the Python standard library.

Step 1: the strategies

Each strategy is a function of the two histories (own moves, opponent moves), possibly with a random generator for random strategies. We use eight classic ones:

  • ALLC / ALLD: always cooperate / always defect.
  • TFT: tit-for-tat.
  • TF2T: tit-for-two-tats, which defects only after two consecutive defections.
  • GRIM: cooperates until the first defection, then defects forever.
  • PAVLOV: "win-stay, lose-shift": repeat the last move if the last payoff was good (R or T), else switch.
  • RANDOM: cooperates with probability 1/2.
  • JOSS: like tit-for-tat but defects 10 percent of the time after cooperation ("sneaky").
Python Strategies and a match

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Step 2: the round robin

Each strategy plays every other strategy (and itself, as in Axelrod's original), and we add up the average score per round. To reduce luck, each pairing is repeated with several random seeds.

Python Round-robin tournament

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the pattern: ALLD never wins against everybody but exploits the naive strategies; nice and retaliating strategies (TFT, GRIM, TF2T, PAVLOV) do well among each other. With noise, a mistake between two TFT players starts a long chain of retaliation, so more forgiving strategies like TF2T and PAVLOV hold up better.

Step 3: evolution of the population

Now treat the tournament as a payoff matrix for replicator dynamics. Each strategy starts with an equal share, and each generation a strategy's share grows in proportion to its average payoff against the current population.

Python Evolving the population

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You will see ALLD collapse within a handful of generations: it earns little against the retaliators (TFT, GRIM, TF2T, PAVLOV), and only the naive ALLC feeds it. The reciprocators then share the population, and ALLC survives as a harmless passenger because, with no defectors left, it scores as well as they do. ALLD does best when many naive cooperators are present.

Step 4: what makes a strategy good?

Axelrod's analysis of the winners gave four properties:

  1. Nice: never defect first.
  2. Retaliatory: punish defection promptly, so you are not a pushover.
  3. Forgiving: return to cooperation when the other does, so mistakes do not become permanent feuds.
  4. Clear: easy for the opponent to understand, so that they learn that cooperation pays.

Later tournaments with noise favored generous versions of tit-for-tat, and evolutionary experiments found "zero-determinant" strategies that unilaterally control the opponent's payoff. A strategy's success also depends on who else is in the pool, which is why a tournament result is never a theorem.

Extensions to try

  • Add your own strategy: a TFT with forgiveness probability or one that detects a pure ALLD opponent after 5 rounds and stops cooperating.
  • Add noise to the evolutionary run (compute the payoff matrix with 5 percent noise and average several seeds).
  • Change the payoffs so that T + S > 2R and see why strategies that alternate between exploiting and being exploited now beat mutual cooperation.
  • Use a shorter game (10 rounds) and see which strategies suffer.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which of these is not one of the properties of successful strategies in Axelrod's tournaments?

    Success came from earning high payoffs overall, not from beating each opponent in head-to-head matches. Tit-for-tat never beats anyone but scores well.
  2. 2. Why does noise hurt tit-for-tat pairs?

    Two TFT players alternate punishing each other after a mistake, which is why more forgiving strategies do better with noise.
  3. 3. In the evolutionary run, why does ALLD die out?

    Defection pays only against exploitable strategies like ALLC; against retaliators it earns about the punishment payoff.
  4. 4. Why is a tournament result not a theorem about the best strategy?

    A strategy that thrives among naive players can fail among sophisticated ones.

Summary

  • A tournament needs a strategy interface, a match function, noise handling and a scoring loop.
  • Nice, retaliatory, forgiving and clear strategies score well; ALLD exploits only naive opponents.
  • Noise rewards forgiving variants of tit-for-tat.
  • Replicator dynamics on the tournament's payoff matrix shows how populations evolve.
  • Results depend on the pool of opponents, so treat them as evidence, not proof.

Next: Project: An Auction Simulator