♟️ Nash Equilibrium — The Maths of Strategy
In a Nash equilibrium no player can do better by changing strategy alone. Explore payoff matrices, best-response dynamics and mixed strategies in classic 2-player games.
About this simulation
This tool lets you build a 2×2 payoff matrix (a table listing each player's reward for every pair of strategy choices) for two players and watches the game play out. It underlines each player's best response (the strategy that maximises their payoff given the opponent's choice) in every cell, boxes any cell where both players are simultaneously best-responding — a pure-strategy Nash equilibrium — and solves the indifference equations for the mixed-strategy equilibrium, where each player randomises between strategies with a specific probability. An animated token then runs best-response dynamics: players alternate switching to whatever is currently their best move, so you can watch play converge on an equilibrium or cycle forever.
🔬 What it shows
A 2x2 payoff matrix with the row player's payoff shown top-left (green when it is a best response) and the column player's payoff shown bottom-right (blue when it is a best response) in every cell. Boxed cells are pure Nash equilibria. A second "Best-response correspondence" view plots both players' best-response curves in (p, q) probability space, marking where they cross.
🎮 How to use it
Pick a classic game from the preset dropdown (Prisoner's Dilemma, Stag Hunt, Battle of the Sexes, Chicken, Matching Pennies) or type your own payoffs into the four "row,col" boxes — you can also click a cell on the canvas to edit it directly. The Speed slider controls how fast the best-response token moves; View switches between the matrix and the correspondence plot; Pause/Play, Step and Reset control the animation.
💡 Did you know?
John Nash's 1950 existence proof, barely a page long, relies on Kakutani's fixed-point theorem to show every finite game has at least one equilibrium (possibly mixed). Matching Pennies, included as a preset here, has no pure equilibrium at all — only a mixed one at p = q = 0.5, which is exactly why the best-response token never settles down and instead cycles.
Frequently asked questions
How does the simulation decide which payoff is a "best response"?
For each column the code compares the row player's two payoffs in that column and marks the larger one (rowBRset); for each row it compares the column player's two payoffs in that row (colBRset). If both numbers in a comparison are equal it treats both strategies as tied best responses. A cell is boxed as a pure Nash equilibrium only when the row payoff is a best response down its column AND the column payoff is a best response across its row at the same time.
How is the mixed-strategy equilibrium (p, q) calculated?
The simulation solves the indifference conditions directly from the payoff numbers. It finds p (the probability the row player plays their first strategy) so that the column player is indifferent between their two options, and q (the probability the column player plays their first strategy) so that the row player is indifferent. Algebraically p = (d22-d21)/(d11-d12-d21+d22) using the column player's payoffs, and q is the mirror formula using the row player's payoffs. If either denominator is zero, or the result falls outside [0,1], no valid mixed equilibrium exists and the stat shows a dash.
Why does the token keep moving even after a pure equilibrium is found?
Best-response dynamics in this simulation is a fixed alternating process: on every step the row player (or column player, alternating by turn) jumps to their current best response, regardless of whether the resulting cell is an equilibrium. Once the token lands on a boxed cell, both players' best responses point back at that same cell, so the token simply keeps landing there step after step — it looks stationary because it genuinely is, but the loop never explicitly "stops."
Why does Matching Pennies never settle down?
In Matching Pennies every cell has exactly one player wanting to switch, so there is no pure Nash equilibrium at all in this preset. Best-response dynamics therefore cycles through all four cells (Heads,Heads) → (Heads,Tails) → (Tails,Tails) → (Tails,Heads) → back to start, forever. The only equilibrium is the mixed one at p = q = 0.5, visible as the yellow dot at the centre of the correspondence view, which the alternating pure-strategy dynamics can never actually land on.
What does the "Best-response correspondence" view actually plot?
It draws p (probability row plays their first strategy) against q (probability column plays their first strategy) on a unit square. The green curve is the row player's best response p*(q) for every possible q, and the blue curve is the column player's best response q*(p) for every possible p, each computed directly from the expected-payoff formulas in the code. Blue dots mark the pure equilibria at the square's corners; a yellow dot marks the mixed equilibrium wherever the two curves genuinely intersect inside the square.
In a Nash equilibrium no player can do better by changing strategy alone. Explore payoff matrices, best-response dynamics and mixed strategies in classic 2-player games.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install