The Prisoner's Dilemma is a classic problem in game theory. Two prisoners (players) are interrogated separately and must each decide, without communication, whether to cooperate (stay silent) or defect (betray the other). The iterated version plays this game over many rounds, allowing strategies based on past decisions to emerge.
Robert Axelrod's famous 1980 computer tournament invited Game Theorists to submit strategies to compete against each other. The best performing strategy was the deceptively simple Tit for Tat, written in just 4 lines of BASIC: cooperate on the first round, then mirror the opponent's last move (retaliate when and only when the opponent defects).
The following conditions are required for a valid Iterated Prisoner's Dilemma:
| Outcome | Symbol | Points | Condition |
|---|---|---|---|
| Temptation | T | 5 | You defect, opponent cooperates |
| Reward | R | 3 | Both cooperate |
| Punishment | P | 1 | Both defect |
| Sucker | S | 0 | You cooperate, opponent defects |
Your code runs as a JavaScript function body with these variables as input parameters:
myMoves — array of your past moves (true=cooperate, false=defect)opponentMoves — array of opponent's past movesround — current round index, 0-based. Size of each array is equal to the current round.
Return true to cooperate or false to defect.
See the provided algorithms for examples.
Note that returning anything other than true will internally default to returning false.