NetLogo banner

 Contact Us

 Modeling Commons

 User Manuals:


NetLogo Models Library:
Sample Models/Social Science/Unverified/Prisoner's Dilemma

Note: This model is unverified. It has not yet been tested and polished as thoroughly as our other models.

(back to the library)

PD Two Person Iterated

[screen shot]

If you download the NetLogo application, this model is included. (You can also run this model in your browser, but we don't recommend it; details here.)


This model is an iterated version of the prisoner's dilemma. If you are unfamiliar with the basic concepts of the prisoner's dilemma, please refer to the PD Basic model found in the Prisoner's Dilemma suite.


The PD Basic model presents an interesting problem: In order to minimize the overall jail time you would cooperate with your partner and remain silent and not confess. However, the rational choice is to defect against your partner by confessing. If your partner does not confess you will go free. If your partner confesses, you will go to jail for three years, much better than the five you would have earned had you refused to confess. Unfortunately, your partner is in the same position. Acting rationally, you will both be worse off.

The dilemma is made more interesting when you know you will interact with the person again. Let us consider the case where you and a friend are chosen for a research study to play the prisoner's dilemma game; only instead of the payoffs being years of jail time, they are money.

The researchers separate you and your friend into separate rooms allowing communication to occur only through a computer. They give you a sheet with the rules for the iterated prisoner's dilemma that reads as follows:

  1. This game will consist of an unspecified number of rounds. At the end of the game, you will receive $1 for each point you have earned.

  2. Each round you and your partner will have the opportunity to earn points by choosing to either cooperate (C) or defect (D). Communication will be done only through the computer. The only message you will be able to pass is cooperate or defect. Neither person will see the other's message until both have chosen their action.

  3. Your payoff for each round will determined by the actions as follows:

<table border> <tr><th><th colspan=2>partner's action <tr><th>your action<th>C<th>D <tr><td>C<td>3<td>0 <tr><td>D<td>5<td>1 </table>

(Note: This way of determining your payoff is the opposite of the PD Basic model. In PD Basic, you were "awarded" something bad --- jail time. In this model, you are awarded something good --- money.)

Your partner has an identical payoff matrix.

To get things started, the model assumes that the user and the computer already played a round where they cooperated with each other, so both players start with a score of 3.



SETUP: Begin playing the iterated prisoner's dilemma. If you choose to turn the SELECT-COMPUTER-STRATEGY? switch off before pressing this button, the computer's strategy will be randomly chosen at this time.

PLAY ONCE: Play a single round of the prisoner's dilemma with the strategy you have selected.

PLAY REPEATEDLY: Repeatedly play rounds of the prisoner's dilemma between you and the computer. You can change your strategy at any time. If the SELECT-COMPUTER-STRATEGY? switch is on you can also change the computer's strategy at any time.

With both PLAY buttons, the computer's action each round will be displayed in the command center.


SELECT-COMPUTER-STRATEGY?: If on, you may select the computer's strategy using the computer strategy slider. If off, the computer's strategy will be randomly chosen from the strategy list found below, excluding the Custom Strategy.

DISPLAY-HISTORY?: Turn on or off messaging in the command center.


HUMAN-STRATEGY - Select your strategy from the list below.

COMPUTER STRATEGY - Select the computer's strategy from the list below.


  • Act-Randomly - randomly cooperate or defect
  • Cooperate - cooperate always
  • Defect - defect always
  • Tit-for-Tat - If the opponent cooperates this round cooperate next round. If the opponent defects this round, defect next round. Initially cooperate.
  • Tit-for-Two-Tats - If the opponent cooperates this round cooperate next round. If the opponent defects two rounds in a row, defect the next round. Initially cooperate.
  • Unforgiving - Cooperate always unless the opponent defects once. Upon opponent defection retaliate by defecting always.
  • Custom-Strategy - This strategy is intended to be written by you. It currently defaults to Tit-for-Tat.


HUMAN SCORE - The total points you have earned

COMPUTER SCORE - The total points the computer has earned


AVERAGE SCORE: The average scores of you and the computer each round vs. the number of iterations. This is a good indicator of how well you are doing relative to the maximum possible average of $5 per round.


Should the computer always play the "Cooperate" strategy, then which strategy for the user results in the highest score?

If the computer always plays "Defect", then what is the nature of the average score plot when the user plays "Tit-for-Tat", "Tit-for-Two-Tat", "Unforgiving", and "Custom Strategy"? Why does such a nature arise for these combination of strategies?

What is the nature of the plot for average score when the computer always plays "Tit-for-Tat" and the user plays every strategy except "Defect" and "Act-Randomly"? Why does such a curve arise?


  1. Turn the SELECT-COMPUTER-STRATEGY? switch off. Setup the model and play the iterated prisoner's dilemma against the computer. You may choose between selecting your strategy each round using the PLAY ONCE button, or automating your choices each round using the PLAY REPEATEDLY button. What approach wins you the most money?

  2. Turn the SELECT-COMPUTER-STRATEGY? switch on. Experiment with playing different strategies against one another. Which strategies do the best? Which do the worst? Why?

  3. Repeat task 1 several times. How does the best strategy vary? Based on you experience in task 2, why might this be so?

  4. The researchers now tell you that they will double the amount of money the person with the most points gets at the end, but the other person will get nothing. In the event of a tie, each person still receives $1 per point. How does this change your strategy? Why?

  5. Describe a real life scenario that is similar to the iterated prisoner's dilemma, preferably one you have experienced. How might the strategies examined here relate to actions taken in that scenario?


Even the most complex strategies in this model are relatively simple. Surely you can do better. Redefine the CUSTOM-STRATEGY procedure attempting to develop a strategy that can earn a higher score than those presented in the model or a human player. Test it against the other strategies and yourself. What are its strengths? What are its weaknesses? Try to keep improving it.

Examine the PD N-PERSON ITERATED model


The model uses the turtle variable label to display each turtle's average score in the view.

The model uses the run primitive to execute the procedure whose name corresponds to the chosen strategy.


PD Basic, PD N-Person Iterated, PD Basic Evolutionary


If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

Please cite the NetLogo software as:


Copyright 2002 Uri Wilensky.


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at

This model was created as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227.

(back to the NetLogo Models Library)