PD Two Person Iterated

PD Two Person Iterated preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)


social science 

Tagged by Reuven M. Lerner almost 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 516 times • Downloaded 89 times • Run 1 time
Download the 'PD Two Person Iterated' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


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:

partner's action
your actionCD

(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.



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.


Random - 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

ITERATION - The number of rounds that have been played


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 plays strategy #1 (cooperate), then which strategy for the user results in the highest score?

If the computer always plays strategy #2 (defect), then what is the nature of the average score plot when the user plays strategy #3 - #6 (Tit-for-Tat, Tit-for-Two-Tat, Unforgiving, and Custom Strategy, respectively)? 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 strategy #3 and the user plays every startegy except strategy #2 (defect) and strategy #0 (random)? 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


Note the use of the turtle variable label to display each turtle's average score in the view.

Note that the set-action procedure takes an input that must be supplied when the procedure is called.


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


If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:


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 http://creativecommons.org/licenses/by-nc-sa/3.0/ 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 uri@northwestern.edu.

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.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [ users user ]
breed [ computers computer ]

globals [

turtles-own [
  score                  ;;my current score
  defect-now?            ;;what will I do this round?
  partner                ;;the who of my partner
  partner-defected?      ;;did my partner defect last round?
  partner-defected-past? ;;did my partner defect two rounds ago?

to setup
  ;;place the computer
  create-computers 1 [
    set partner 1
    set shape "computer"
    set heading 90
    fd max-pxcor / 2
  ;;place the human
  create-users 1 [
    set partner 0
    set shape "person"
    set heading 270
    fd abs min-pxcor / 2
  ;;initially assume you and your partner have always cooperated
  ask turtles [
    set defect-now? false
    set partner-defected? false
    set partner-defected-past? false
    set size 10
    set label 3.0
  ;;choose the secret strategy the computer will play if select-computer-strategy? is off
  set hidden-strategy random 6

;;; Runtime Procedures;;;

to play
  ;;choose strategy
  ask users [ set-action human-strategy ]
  ;;update the displayed score in the view
  ask turtles [ set label precision (score / ticks) 3]

to play-a-round
  ;ask each turtle to select its strategy
  ifelse select-computer-strategy?
    [ask computers [ set-action computer-strategy ]]
    [ask computers [ set-action hidden-strategy ]]
  ;based upon the strategy each agent has chosen, determine this round's payoffs
  ask turtles [ get-payoff ]

to prepare-next-round
  set computer-score [score] of turtle 0
  set human-score [score] of turtle 1
  ;;display the computer's action in the last round
  if display-history? [
    ask users [
      ifelse partner-defected?
        [output-print "Last turn your partner defected"]
        [output-print "Last turn your partner cooperated"]
    output-print "Choose your action"

to set-action [strategy ] ;;Turtle Procedure
  ;;call the strategy based on the number passed through
  if (strategy = "random") [ act-randomly ]
  if (strategy = "cooperate") [ cooperate ]
  if (strategy = "defect") [ defect ]
  if (strategy = "tit-for-tat") [ tit-for-tat ]
  if (strategy = "tit-for-two-tats") [ tit-for-two-tats ]
  if (strategy = "unforgiving") [ unforgiving ]
  if (strategy = "custom-strategy") [ custom-strategy ]

;;; Strategies ;;;

to act-randomly ;;Turtle Procedure
  ifelse (random 2 = 0)
    [set defect-now? false]
    [set defect-now? true]

to cooperate  ;;Turtle Procedure
  set defect-now? false

to defect ;;Turtle Procedure
  set defect-now? true

to tit-for-tat ;;Turtle Procedure
  ifelse partner-defected?
    [ set defect-now? true ]
    [ set defect-now? false ]

to tit-for-two-tats ;;Turtle Procedure
  ifelse (partner-defected? and partner-defected-past?)
    [set defect-now? true]
    [set defect-now? false]

to unforgiving ;;Turtle Procedure
  ifelse (partner-defected? or defect-now?)
    [set defect-now? true]
    [set defect-now? false]

to custom-strategy ;;Turtle Procedure
  ;;Currently defaults to tit-for-tat.  Can you do better?
  ifelse partner-defected? ;;partner defected stores your partner's action last round
    [set defect-now? true]
    [set defect-now? false]

;;; End Strategies ;;;

to get-payoff ;;Turtle Procedure
  set partner-defected-past? partner-defected?
  set partner-defected? [defect-now?] of turtle partner
  ifelse partner-defected?
    [ifelse defect-now?
      [set score score + 1]
      [set score score + 0]
    [ifelse defect-now?
      [set score score + 5]
      [set score score + 3]

; Copyright 2002 Uri Wilensky.
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky about 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky over 11 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky about 14 years ago PD Two Person Iterated Download this version

Attached files

File Type Description Last updated
PD Two Person Iterated.png preview Preview for 'PD Two Person Iterated' about 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.