🎮 Game Theory — Prisoner's Dilemma & Evolutionary Strategies
A grid of agents repeatedly plays the Prisoner's Dilemma. Each round, every agent plays
against its 8 neighbours and earns a payoff. Then each agent adopts the strategy of its
highest-scoring neighbour (with optional noise). Watch cooperation emerge, collapse, or
cycle depending on the strategy mix and payoff values.
Legend
Always Cooperate (AC)
Always Defect (AD)
Tit-for-Tat (TFT)
Pavlov (WIN-STAY)
Random (50/50)
Payoff Matrix
C
D
C
R=3
S=0
D
T=5
P=1
Grid & Speed
Presets
Stats
Cooperators—
Defectors—
Mean payoff—
Round #0
The Prisoner's Dilemma
Two agents can Cooperate (C) or Defect (D). The payoff ordering T > R > P > S and
2R > T + S makes mutual cooperation better collectively, but individual incentive pushes
toward defection. This tension is the core of the dilemma.
Nash Equilibrium vs. Pareto Optimum
In a one-shot game, mutual defection (P, P) is the Nash equilibrium — neither
player can improve by switching unilaterally. Yet mutual cooperation (R, R) is
Pareto optimal — you cannot make one agent better off without hurting the other.
Rational self-interest leads to a suboptimal outcome. This is the tragedy of the dilemma.
Why Tit-for-Tat wins
In Robert Axelrod's famous tournaments (1980), Tit-for-Tat (start cooperative, then mirror
opponent's last move) won against 62 strategies. TFT is nice (never defects first),
retaliatory (punishes defection immediately), forgiving (returns to
cooperation after one retaliation), and clear (easy to read). In spatial settings
TFT clusters protect it from exploitation.
Real-world applications
Climate agreements — nations defect (emit CO₂) even though cooperation benefits all
Arms races — mutual disarmament is Pareto superior but unilateral disarmament is exploited
Antibiotic resistance — bacteria that produce common goods face defector mutants
Price wars — companies could cooperate on prices but individually undercut competitors
About Evolutionary Game Theory
This simulation runs the spatial Prisoner's Dilemma on a toroidal grid of agents (40×40 by default). Each round, every cell plays the dilemma against all eight of its Moore-neighbourhood neighbours and accumulates a payoff from the matrix T > R > P > S. Agents then evolve by imitation: each copies the strategy of whichever neighbour (including itself) scored highest that round, with a small chance of random mutation.
The sliders set the four payoffs — Temptation, Reward, Punishment and Sucker — while others adjust grid size, simulation speed and noise (mutation rate). Five strategies compete: Always Cooperate, Always Defect, Tit-for-Tat, Pavlov (Win-Stay Lose-Shift) and Random. The same logic explains cooperation in climate treaties, arms races, antibiotic-resistance ecology and corporate price wars, where individual incentives clash with collective benefit.
Frequently Asked Questions
What does this simulation actually show?
It shows how cooperation can emerge, collapse or cycle when many agents repeatedly play the Prisoner's Dilemma on a grid. Each coloured cell is an agent running one of five strategies, and over successive rounds the more successful strategies spread across the population through imitation.
How does the evolution rule work?
After every round each agent looks at its own score and the scores of its eight neighbours, then adopts the strategy of whichever one earned the most points that round. This "imitate the best neighbour" rule is a standard form of spatial evolutionary dynamics — no genetics or reproduction, just copying of successful behaviour.
What do the T, R, P and S sliders control?
They set the four payoffs of the dilemma: Temptation (defect against a cooperator), Reward (mutual cooperation), Punishment (mutual defection) and Sucker (cooperate against a defector). A genuine dilemma needs T > R > P > S, and ideally 2R > T + S so that mutual cooperation beats alternating exploitation.
What are the five strategies?
Always Cooperate (green) and Always Defect (red) ignore the opponent. Tit-for-Tat (blue) repeats the neighbour's last move towards it. Pavlov, or Win-Stay Lose-Shift (purple), keeps its move if the last payoff was good and switches if it was poor. Random (amber) cooperates or defects with a 50/50 coin flip each interaction.
Why does Tit-for-Tat usually do so well?
In Robert Axelrod's 1980 tournaments Tit-for-Tat beat 62 rival strategies because it is nice (never defects first), retaliatory (punishes defection at once), forgiving (returns to cooperation immediately) and clear. On a grid, clusters of TFT agents shield one another from exploitation, letting cooperation hold a foothold even amid defectors.
What is the difference between a Nash equilibrium and a Pareto optimum here?
In a one-shot game mutual defection is the Nash equilibrium: neither player can gain by switching alone. Mutual cooperation is the Pareto optimum: you cannot improve one agent without harming the other. The tragedy of the dilemma is that rational self-interest drives players to the worse, Nash outcome.
What does the noise slider do?
Noise sets a mutation rate, from 0 to 20 per cent. After the imitation step, each agent has that probability of instead adopting a randomly chosen strategy. A little noise keeps the system from freezing into a single absorbing state and lets new strategies be re-seeded so the dynamics stay lively.
Is the spatial structure important?
Yes. Because agents only interact with eight immediate neighbours rather than the whole population, cooperators can form protective clusters whose interior members all cooperate and score well. This local structure is exactly why cooperation survives spatially when it would be wiped out in a well-mixed population.
What do the presets do?
All Defectors seeds a sea of defectors with a tiny TFT core to test invasion; TFT Invasion uses a larger cooperative cluster; Pavlov World fills the grid mostly with Pavlov agents; and Mixed starts from a weighted blend of all five strategies. They are quick ways to explore which configurations let cooperation take hold.
How accurate is this compared with real game theory?
The payoff matrix, strategy definitions and Nash and Pareto analysis are faithful to standard theory, and the imitate-best dynamic is a recognised model used by Nowak and May. It is a simplified teaching tool, though: real ecologies involve continuous strategies, memory of many past rounds and reproduction rather than pure copying.
Where does the Prisoner's Dilemma appear in the real world?
It models any situation where private incentives undermine shared gains: nations emitting carbon despite a collective interest in restraint, rivals locked in arms races, bacteria producing public goods that cheaters exploit, and firms tempted to undercut a mutually profitable price. The simulation hints at how repetition and structure can rescue cooperation.