This is an implementation of the prisoner's dilemma applied to a spatial grid, based on a well-known paper by Nowak and May.
Cooperator | |
Defector |
Cooperator (new) | |
Defector (new) |
Each little cell represents a critter. They play the game with their neighbors, and the highest-scoring critters reproduce to occupy new cells. Cooperators playing each other score 1 point each, defectors playing cooperators score B points all for themselves, and defectors playing defectors score nothing.
Even with such simple rules, complex patterns appear. The value of B represents the advantage given to defectors. Small variations in B can cause the equilibrium to shift wildly, illustrating the fragility and yet surprising robustness of cooperative behavior in a system governed by natural selection.
The simulation runs mostly as per the original paper. There's also a toggle which color-codes cells by score and allows them to keep their score between turns, which I thought had interesting enough effects to include!