ForHosting KIT · Math

Prisoner's dilemma calculator

Score one round of the prisoner's dilemma: pick cooperate or defect for each player and get both scores. With the classic table, two cooperators earn 3 each, and a defector facing a cooperator takes 5 and leaves 0. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Choice a
Cooperate
Choice b
Cooperate
You get
Temptation
5
Reward
3
Punishment
1
Sucker
0

The prisoner's dilemma is the canonical two-player game in which each person independently chooses to cooperate or defect, and both scores come from a single 2-by-2 payoff matrix. This prisoner's dilemma calculator accepts player A's action, player B's action, and the four textbook payoffs temptation, reward, punishment, and sucker, then returns both players' scores for that one simultaneous round. Mutual cooperation pays the reward to each side; mutual defection pays the punishment to each side; a mixed pair pays temptation to the defector and the sucker payoff to the cooperator.

What the four-cell matrix means and how both scores appear

The prisoner's dilemma is not a story about guilt; it is a 2-by-2 bimatrix in which two players choose simultaneously from the same action set, cooperate or defect, and each receives a number from a four-cell payoff table. Convention names those four numbers after the story they tell. Reward, written R, is what each player earns when both cooperate.

Temptation, written T, is what a player earns by defecting against a cooperator. Sucker, written S, is what a cooperator earns against a defector. Punishment, written P, is what each player earns when both defect.

Reading the table from player A's point of view, the cells are therefore the pair (R, R) on mutual cooperation, the pair (S, T) when A cooperates and B defects, the pair (T, S) when A defects and B cooperates, and the pair (P, P) on mutual defection. A matrix is a prisoner's dilemma, in the strict textbook sense used here, when temptation strictly exceeds reward, reward strictly exceeds punishment, punishment strictly exceeds sucker, and twice the reward strictly exceeds temptation plus sucker.

Those inequalities make defect the unique strictly dominant strategy and make mutual defection the unique pure Nash equilibrium of the one-shot game, even though mutual cooperation is jointly better for the pair. This calculator looks up the cell that matches the two submitted choices, returns both scores, and also reports whether the supplied numbers still satisfy those inequalities and whether the submitted profile is a Nash equilibrium.

It does not simulate repeated play, mixed strategies, cheap talk, or tit-for-tat; it scores one simultaneous round and stops there so the contract stays deterministic.

Classroom and homework checks

Let students submit cooperate or defect for both players and verify both scores, the named outcome, and whether mutual defection is the Nash equilibrium on the assigned matrix.

Exam and LMS auto-grading

Mark one-shot prisoner's dilemma items with a deterministic oracle that rejects unknown actions and never invents a payoff cell.

Lab and product 2-by-2 scoring

Score a fixed T,R,P,S matrix in an experiment, a public-goods demo, or a two-firm pricing notebook without copying spreadsheet formulas.

How do I compute prisoner's dilemma payoffs for one round?

Optional temptation, reward, punishment, and sucker default to 5, 3, 1, and 0.

Can I change the temptation, reward, punishment, and sucker values?

Yes. Override any of the four finite payoffs.

Why is mutual defection the Nash equilibrium in the prisoner's dilemma?

Because defecting pays more whatever the other player does: 5 instead of 3 against a cooperator, and 1 instead of 0 against a defector. Neither player gains by switching alone, even though cooperating together would give each of them more.

What makes a payoff table a true prisoner's dilemma?

Temptation must beat reward, reward must beat punishment, punishment must beat the sucker's payoff, and twice the reward must exceed temptation plus sucker. The calculator tells you whether your numbers still meet all four conditions.

Does the calculator simulate repeated rounds or tit-for-tat?

No. It scores a single round in which both players choose at the same time, and stops there. Play over many rounds, strategies such as tit-for-tat and mixed strategies are outside what it works out.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/math/prisoners-dilemma

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/math/prisoners-dilemma \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"choice_a":"cooperate","choice_b":"cooperate"}'
{
  "choice_a": "cooperate",
  "choice_b": "cooperate"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.prisoners_dilemma",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

A choice that is not cooperate or defect fails with invalid_input instead of inventing a cell in the matrix.

Input contract, response shape, and error behaviour

Common textbook abbreviations are accepted when the canonical word is omitted: c or coop for cooperate, and d or def for defect. The payoff matrix defaults to the Axelrod tournament numbers temptation 5, reward 3, punishment 1, and sucker 0. Example: both cooperate on the default matrix yields scores 3 and 3. Example: A defects and B cooperates yields scores 5 and 0. POST a JSON body with two required actions and, optionally, four finite payoffs. choice_a is player A's action and choice_b is player B's action; each must be cooperate or defect after trimming and ignoring case. Aliases player_a, player1, and a resolve to choice_a; player_b, player2, and b resolve to choice_b. Missing actions, empty strings, and any other token such as attack, stay silent, yes, or the integer 1 fail with invalid_input that names the field and states that the expected values are cooperate or defect; those failures are not billed. You may override any of those four with a finite JSON number or a numeric string; non-finite values fail naming the field. On success the body echoes the normalized choices and the four payoffs, returns score_a and score_b as the primary result, names the outcome as mutual_cooperation, a_defects, b_defects, or mutual_defection, and reports social_welfare as the sum of the two scores. It also flags is_prisoners_dilemma when the four numbers satisfy the textbook inequalities, flags is_nash when neither player can improve by unilaterally switching, restates the cell map in formula, and includes a one-line message you can print next to a matrix. Pair the payload with your own drawing of the 2-by-2 table; this endpoint does not emit plots or multi-step classroom prose beyond the message and formula fields.

Where a one-round prisoner's dilemma API earns its keep

Classrooms and tutoring platforms use a prisoner's dilemma calculator so learners can check both scores for every pair of actions without flipping T and S by hand or confusing the social sum with a single player's payoff. Laboratory and classroom experiments in economics and political science often fix a matrix in advance and then need an independent scorer that will not drift when a spreadsheet formula is copied one cell too far. Failed validation does not consume balance. Exam-prep generators need a deterministic oracle that marks an invalid action as invalid_input instead of silently mapping an unknown string onto cooperate. Product, pricing, and public-goods teams reuse the same 2-by-2 story when two firms choose to advertise or stay quiet, when two countries choose to abate or pollute, or when two users choose to share or free-ride; calling a tiny parse API avoids reimplementing the cell map in every backend language. Keep requests small, pin score_a and score_b in tests, and you get reproducible one-round scores for homework, LMS plugins, and edge workers without standing up a game-theory library of your own.

What if a player sends a choice other than cooperate or defect?

The task fails with invalid_input naming the field. Only cooperate and defect (and the short aliases c, coop, d, def) are valid; unknown tokens are not mapped onto a cell.

Which outcome is the Nash equilibrium?

On a textbook prisoner's dilemma matrix, mutual defection is the unique pure Nash equilibrium because defect strictly dominates cooperate. is_nash is true only when neither player can raise their own score by switching alone.

What does the prisoner's dilemma calculator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →