Prisoner’s Dilemma Tournament

A classic, the iterated prisoner’s dilemma (or tournament) is a fun and relatively simple way to “run a simulation”. One of the reasons of course why it’s so popular to test a language or framework, a person’s qualifications or intelligence or some thoughts you might have yourself on the subject.

A discussion with a friend triggered regained interest. It was about why, when and which strategies are most successful. And if we can draw any conclusions from this or Game Theory in general about human behavior and/or human societies.

Since running a game is so straightforward and player strategies are (mostly) very simple functions I decided to code it in javascript. Yes, I know there are a million versions already, but I had some special requirements. Extensive game debugging and the possibility to add custom strategies.
Right now adding a strategy would be done in the separate JS players file, either on CodePen or on GitHub.

UPDATE. I added a “survival of the fittest” evolution feature. You can now run a series of tournaments, where each time a loser gets eliminated after a specified amount of tournaments. Resulting in a winner. When players tie, the random player strategy is added to the mix as a tiebreaker.
I have been told Darwin never used the term “survival of the fittest”, to him it evolution was more about adaptability. “Mutants” are also added as an option to join the game. The next improvement would be to treat strategies as a “gene pool”. Replication and interaction could then be added to the mix. Using some kind of basic neural network would be cool.

AI. I’ve been checking out Claude Sonnet 4.5 as a coding assistent, Challenged Claude to come up with a winning strategy. I was kind of impressed, the third try already resulted in at least a competitive player (grandmaster).

Both the Codepen and the code on Github is updated.

CodePen

See the Pen Prisoner’s Dilemma Tournament by Status201 (@status201) on CodePen

Github

See the code on GitHub. Feel free to fork or make a pull request!

Leave a Reply