The Prisoner's Dilemma

by Serge Helfrich

The spatial variant of the iterated prisoner's dilemma is a simple yet powerful model for the problem of cooperation versus conflict in groups. The applet below demonstrates the spread of 'altruism' and 'exploitation for personal gain' in an interacting population of individuals learning from each other by experience. Initially the population consists of cooperators and a certain amount of defectors (a fraction represented by p). The advantage of defection is determined by the value of b in the 'payoff matrix' (see below) which is used to calculate the payoff after each round for each 'player' on the basis of its strategy. For the next round, a player determines its new strategy by selecting the most favorable strategy from itself and its direct neighbors.

You can use the links below to learn more about this fascinating topic in 'game theory':


This interactive simulation is inspired by A.L. Lloyd's concept featured in Scientific American (June 1995, 80-83).

The Payoff Matrix
Cooperate Defect
Player Cooperate 1 0
Defect b 0


  • is cooperating, did cooperate
  • is defecting, did defect
  • is cooperating, did defect
  • is defecting, did cooperate

b: advantage for defection when opponent cooperates

p: fraction (0..1) of defectors in the first round

Suggested Experiments

Java Application

A JavaFX application is available on GitHub. Its also provides history charts.