🤝 Public Goods Game & Cooperation (2D)

N players each decide how much to contribute to a shared pot. Multiplier r pays the total back equally. Nash equilibrium says contribute 0 — with punishment or evolution, cooperation can emerge instead.

Game MathInteractive2D
Purple bars = contribution per round · Green line = avg payoff · Dashed = cooperator % · Red/purple dashed = Nash / social-optimum payoff

How it Works

In the public goods game, each of N players receives an endowment E and privately chooses a contribution ci ∈ [0, E]. Total contributions are multiplied by r and divided equally: every player receives r·ΣC/N regardless of their own contribution.

Payoff for player i is: πi = (E − ci) + r·Σjcj/N. The dominant strategy is ci = 0 (free-ride), giving Nash equilibrium payoff = E. If everyone cooperates fully (c = E), each gets r·E — more than E whenever r > 1. The social optimum needs r > 1, but individual rationality pulls toward 0.

Payoff: pi_i = (E - c_i) + r * Sum_j c_j / N Nash equilibrium: c_i* = 0 for all i (when r < N) Nash payoff: pi_NE = E Social optimum: c_i = E, pi_SO = r*E Price of anarchy: r*E / E = r With punishment (cost 0.3 to reduce a free-rider by 1.0): Punisher payoff loses 0.3 per non-cooperator punished Free-rider payoff loses 1.0 per punisher acting on them Cooperation is stable when the punishment ratio outweighs (N-1)

In Evolutionary mode, each round every player observes one random peer and imitates their contribution level if that peer earned more — a simple replicator-dynamics rule. In Punishment mode, a subset of cooperators pay a personal cost to dock free-riders, which can flip enough of them into cooperating that the population average climbs over time.