↑ ↓ to move · enter to open

022 · Game theory · Dominance, Nash equilibrium

prisoner's dilemma

Two suspects sit in separate cells. Each can stay silent or testify against the other. Whatever the partner does, testifying shortens your own sentence, so both testify and both serve longer than if they had kept quiet. Below you can check that cell by cell, play the game hundreds of rounds between strategies, and let the best scorers take over a population.

LAB 1

four cells, one trap

Each cell lists A's years, then B's years. Fewer years is better. The four numbers have names: R reward for mutual silence, P punishment for mutual defection, T temptation for defecting on a silent partner, and S the sucker's sentence. Edit any number (its mirror cell changes too, so the game stays symmetric), then step through each prisoner's reasoning.

payoff matrix · years in prison
B silentB defects
A silent
A defects
(A's years, B's years) · underline = best response
step 8 / 8

How to read this: the table lists each outcome as (A's years, B's years). The map beside it shows the same four outcomes, with an arrow wherever one prisoner would rather switch alone.

  • red struck-out move: never worth picking
  • gold cell: no arrow leaves it, so both stay (equilibrium)
  • green arrow: A would switch this way
  • amber arrow: B would switch this way
  • dashed: no preference

Try this: press From start, then Next, and watch A compare the two rows inside each column (the outlined cells).

—
Pure Nash equilibria
—
Verdict
—
A's dominant move
—
B's dominant move

This step—

CodePython

A cell is a pure Nash equilibrium when each player's move is a best response to the other's: neither can do better by switching alone. In a 2×2 game that is two comparisons per cell. The arrows in the diagram are exactly those comparisons, so an equilibrium is a cell no arrow leaves.

When is it a dilemma?

payoffs: T > R > P > S ⇔ years: T < R < P < S

    LAB 2

    play it a hundred times

    Played once, defection wins. Played again and again against the same partner, today's move can be punished or rewarded tomorrow. Seven strategies meet in a round robin using the sentences from Lab 1. Each pair plays a match of N rounds, and every move can flip by mistake with the noise probability. Click a cell of the grid to watch that match.

    Standings · average years per round · shorter bar = less prison = better · gold = winner
    Head to head · row's years per round against column
    • row did well (few years)
    • row did badly (many years)
    • gold border: the match shown below
    Match history
    silent (C)defect (D)a mistake flipped this movereplay position
    100
    0%
    —
    Lowest average sentence
    —
    Its years per round
    —
    Always Defect finishes
    —
    This match · years

    This match—

    CodePython

    The strategies

    Tit for Tat starts silent, then copies the partner's last move. Grim Trigger stays silent until the first defection, then defects forever. Pavlov (win-stay, lose-shift) repeats its move after a good outcome and switches after a bad one, which works out to "stay silent if we both made the same move last round". Tit for Two Tats defects only after two defections in a row.

    In 1980 Robert Axelrod ran computer tournaments of the repeated game with strategies submitted by researchers. Tit for Tat, submitted by Anatol Rapoport, won. Turn the noise up and watch how it fares when one mistake can start a long feud between two copies of it.

    LAB 3

    let the winners multiply

    Now treat the strategies as a population. Each generation everyone plays everyone, and a strategy's share grows in proportion to its average score. This is the discrete replicator equation. Scores are points per round, points = max sentence − years, so higher is better and nobody scores below zero. Matches here are noise-free and use the sentences from Lab 1.

    population share
    33%
    10 120

    How to read this: each line is one strategy's share of the population over the generations. A rising line is a strategy that is winning. The two thick lines are Always Defect and Tit for Tat, and the dashed gold line marks the current generation while it runs.

    Try this: pick "Defectors vs Tit for Tat", then drag "Always Defect at start" until Tit for Tat drops below its threshold (shown in the panel text) and watch the outcome flip. The chip buttons add or remove strategies.

    —
    Generation
    —
    Largest share now
    —
    Always Defect share
    —
    Tit for Tat needs, vs Always Defect

    Now

    CodePython

    Why Tit for Tat holds

    x·a + (1−x)·b > x·c + (1−x)·d ⇔ x > (d − b) / ((a − c) + (d − b))

    Let x be Tit for Tat's share in a population with only Always Defect. Here a is what Tit for Tat scores against itself, b against a defector, c what a defector scores against Tit for Tat and d against another defector. Tit for Tat loses only the first round to a defector, then defects back, while two copies of it stay silent the whole match. With enough rounds that beats the defector's one-time gain, so once Tit for Tat passes the threshold it grows.

    Always Cooperate has no such defense: it scores less than a defector against every opponent, so any defectors among naive cooperators take over. In a single round (set rounds to 1) Tit for Tat is just a cooperator, and it loses too.