Every cell of the grid is an individual playing the iterated, spatial prisoner's dilemma against its four grid neighbours. Each round it either cooperates or defects depending on its strategy and what those same neighbours did to it last round. Mutual cooperation pays R = 3 to both; mutual defection pays P = 1 to both; when one defects and the other cooperates the defector earns the temptation payoff T (adjustable) while the cooperator earns the sucker's payoff S = 0.
payoff(C,C)=R payoff(D,D)=P
payoff(D,C)=T payoff(C,D)=S
next(agent) = strategy of best-scoring neighbour, ± mutation
After each round of play, every individual looks at itself and its four neighbours and adopts whichever strategy earned the highest score that round — a simple model of social learning / differential reproduction. A small mutation chance keeps rare strategies from vanishing entirely, mirroring genetic drift.
- Always Cooperate (green) — cooperates unconditionally; easy prey for defectors nearby.
- Always Defect (red) — defects unconditionally; wins fast locally but starves once surrounded by other defectors (P < R).
- Tit-for-Tat (blue) — starts cooperating, then mirrors whatever that specific neighbour did to it last round.
- Grudger (purple) — cooperates until a neighbour defects against it even once, then defects against that neighbour forever.
- Pavlov (orange) — win-stay/lose-shift: repeats its last move if it scored well against that neighbour, switches otherwise.
- Random (yellow) — cooperates or defects with 50/50 odds, ignoring history.
Raising the temptation payoff makes betrayal individually more rewarding and tends to favour defectors; raising mutation reintroduces cooperators even after they are wiped out, which is often what lets reciprocal strategies like tit-for-tat and Pavlov recover and spread — the same dynamic evolutionary psychologists point to when explaining why reciprocal altruism can be evolutionarily stable even though pure altruism is not.