The Prisoner's Dilemma

Fork me on GitHub

Grey overlay









Developing the Programming and Development and Algorithm learning strands, specifically:

  • Understands the difference between, and appropriately uses if and if-then and else statements.
  • Uses a variable and relational operators within a loop to govern termination.
  • Designs solutions (algorithms) that use repetition and two-way selection i.e. if, then and else.


Try It

  • The Prisoner's Dilemma is probably the most popular example of game theory in action. It demonstrates that people don't always act in their own best interests.
  • Imagine that two people have been arrested for a crime, and the police are uncertain which person committed the crime and which person helped carry it out.
  • Each prisoner is put into a different room and given a choice:
    • Remain silent
    • Betray your parter by confessing
  • If both stay silent, they will both be sent to prison for 1 year.
  • If they both betray one another, they can both be sent away for 3 years.
  • If one betrays the other, the betrayer goes free, and the other is imprisoned for 5 years.
  • The situation can illustrated using the following payoff matrix:


  • The lowest total amount of prison time somes from both parties cooperating, but there's always the risk that the other person might not be as kind of you.
  • This becomes more interesting if we play the game once, then immediately play it again. Each player will now have a knowledge of how the other person behaved last time, and this will influence their decision making process.
  • If we assign points (based on minimizing time in jail), we can develop different game strategies to minimize the time the human player stays in jail over multiple games.

Learn It

  • The same idea can be seen in different places in human society.
  • Imagine a pair of competing fizzy drinks manufacturers. They both have two options when considering the sales of their products:
    • Option 1: Don't spend money on advertising. People know your product already, and are currently buying it at a steady rate.
    • Option 2: Spend money on advertising. It'll cost money, but sales will increase.
  • If both companies cooperate (option 1), they'll both enjoy steady profits and won't have to spend thousands of pounds on advertising.
  • If one advertises and the other doesn't, one company will see their sales increase as the other company's sales (and profits) drop.
  • If both companies advertise, the effects of them both advertising will cancel each other out, and both companies will see their overall profits drop because of the money they're spending on advertising.

Badge It - Silver

Learning Strand: Programming and Development

Two companies share a market, in which they currently make £5,000,000 each. Both need to determine whether they should advertise. For each company advertising costs £2,000,000 and captures £3,000,000 from the competitor provided the competitor doesn’t advertise. What should the companies do?

  • Using Word's table tool, create a payoff matrix for the above scenario.
  • Explain why in real life, compaines tend to advertise heavily

Code It

  • In a new browser tab, open this link to see a prisoner's dilemma simulator
  • If you've a Scratch account, you can sign in to save the work you'll do here.
  • If you've not got one, you can always click 'File -> Download to your computer' when you're finished to ensure your work is saved.
  • Unfortunately, it looks like the developer didn't have time to finish the code, and there are some blanks.
  • Based on the rules set out above, can you complete the code and make the game work?

Badge It - Gold

Learning Strand: Programming and Development

  • Finish the Scratch code so that the game works as intended, that is:
    1. add an if statement so that the choices of Cat stays silent and you betray will also be checked and the appropriate points awarded or deducted.
    2. add an if statement so that the choices of Cat betrays and you stays silent will also be checked and the appropriate points awarded or deducted.
  • Upload a screenshot of the complete and working code for your Gold badge.

Badge It - Platinum

Learning Strand: Algorithms

  • Change the Scratch code so that when you play against the cat it never betrays you and always let's you off with the best result for you.
  • Upload a screenshot of the complete and working code for your Platinum badge.