Lecture 21 Iterated Prisoner's Dilemma

Joseph Haugh

University of New Mexico

Today’s Topics

  • The Prisoner’s Dilemma: a classic problem in game theory
  • The Iterated version: playing many rounds
  • A 3-player variant and its payoff table
  • Your team exercise: implementing a strategy in Java

Video Explanation

Veritasium Video

The Prisoner’s Dilemma

  • Two players are each asked to cooperate or defect
  • Neither player knows what the other will choose
  • The outcome for each player depends on both choices
  • This models many real situations: arms races, price wars, environmental agreements

2-Player Payoff Table

Opponent Cooperates Opponent Defects
You Cooperate You: 3, Opp: 3 You: 0, Opp: 5
You Defect You: 5, Opp: 0 You: 1, Opp: 1

The Dilemma

  • No matter what your opponent does, defecting gives you more points
    • If they cooperate: defecting gives 5, cooperating gives 3
    • If they defect: defecting gives 1, cooperating gives 0
  • Yet if both defect, each gets only 1
  • If both cooperate, each gets 3, much better for everyone
  • Individual self-interest leads to a worse outcome for both players

Iterated Prisoner’s Dilemma

  • What if you play the same opponent many times in a row?
  • Now your choices have consequences: you can reward or punish past behavior
  • This changes everything, cooperation can emerge as a rational strategy
  • Famous example: Tit-for-Tat
    • Cooperate on round 1
    • Then copy whatever your opponent did last round
  • Simple, but surprisingly effective against many strategies

Why Iteration Matters

  • With a single game, defecting is always rational
  • With many rounds, a player who always defects will be punished in future rounds
  • A player who cooperates can build mutual trust and earn more points over time
  • The best strategy depends on what your opponent does, this is what makes it interesting

3-Player Prisoner’s Dilemma

  • Now there are three players: you and two opponents
  • Each round all three independently choose: cooperate or defect
  • Your score depends on your own move and how many opponents cooperated
  • The more opponents cooperate, the more points you can earn

3-Player Payoff Table

Your Move Opponents Who Cooperated Your Points
Cooperate 2 3
Cooperate 1 1
Cooperate 0 0
Defect 2 5
Defect 1 3
Defect 0 1

Reading the Table

  • Defecting always earns more than cooperating, no matter what opponents do
  • But if all three defect, everyone earns only 1 point per round
  • If all three cooperate, everyone earns 3 points per round
  • The tension is the same as the 2-player version, but now spread across three players

The Exercise

  • You will implement a strategy for the 3-player iterated game in Java
  • Your strategy is a class with two methods:
    • getTeamName()
      • Returns the name of your team as a String
    • decision(history1, history2)
      • history1 is the history of opponent 1’s past moves
      • history2 is the history of opponent 2’s past moves
      • Returns Move.COOPERATE or Move.DEFECT
  • The game runs for a variable amount of rounds, between 150 and 250
  • Your team’s total score is the sum of your points across all rounds

What You Are Given

// Three provided strategies to test against:
new IPD3RandomTeam()   // cooperates or defects randomly
new IPD3AlwaysDefect() // always defects
new IPD3Lenient()      // cooperates unless BOTH opponents defected last round
  • Your class is IPD3Team where you must implement the getTeamName and decision methods
  • The MoveLists passed in have the most recent moves of your opponents first
  • You can look at any number of past rounds to inform your decision
  • You can also add fields to the class to track things such as the round number or other data about your opponents

A Sample Decision Method

Move decision(MoveList history1, MoveList history2) {
    // Always cooperate (naive strategy)
    return Move.COOPERATE;
}
Move decision(MoveList history1, MoveList history2) {
    // Always defect (greedy strategy)
    return Move.DEFECT;
}
  • These are the extremes, your strategy should be more nuanced

Things to Think About

  • Should you cooperate on the first round before you have any information?
  • How do you handle an opponent that sometimes defects vs. one that always defects?
  • Should you treat both opponents independently or react to their combined behavior?
  • Does it matter what round you are on? (e.g., last few rounds)
  • What does Lenient do, and why might it be a reasonable strategy?
  • Remember that everyone has seen the same video about which strategy won the previous tournament…

Team Expectations

  • Implement IPD3Team.java with a non-trivial decision method and getTeamName
  • Test your strategy against the provided opponents (AlwaysDefect, Lenient, Random)
  • Be prepared to explain your strategy and why you chose it
  • We will run a tournament where every team’s strategy plays against every other team’s
  • The team with the highest total score across all matchups wins!