### Prisoner’s Dilemma Visualisation

I recently read Richard Dawkins’ The Selfish Gene and was fascinated with his discussion of Prisoners Dilemma (PD), a classic example of game theory, in relation to evolution. On the lookout for inspiration for my first Processing project, I decided to use this idea to create a visualisation of the game in progress.

First a brief explanation. PD involves two players and a banker. Each player has the choice to either cooperate or defect and are awarded points for the various outcomes of the game. If they both cooperate they each get 3 points, if they both defect, they each get 1 point and if one cooperates and the other defects, the defector gets 5 points and the cooperator gets no points. Iterated PD is where this game is played a number of times. The winner is the player with the most points after the last game has been played. For more detailed information click here.

Within my Processing sketch, there are 8 different “animals”. Each uses a classic PD strategy. They are as follows:

Green = Tit-For-Tat – Always begin by cooperating then copy the last move of the opposition.
Blue = Tit-For-Two-Tats – Like Tit-For-Tat but the opponent must defect twice before the player retaliates.
Red = Always Defect.
Yellow = Random. Each play has a 50% probability.
Purple = Always Cooperate.
Turquoise = Grudger – The player cooperates every move until the opponent defects once. The Grudger defects every move after this.
Orange = Naive Prober – Tit-For-Tat but with random defection.
Grey = Adaptive – Starts with c,c,c,c,c,c,d,d,d,d,d and then makes each choice by calculating the best average scores for defection and cooperation.

Each time two animals come into contact with each other, they have 40 games of Iterated PD. The scores of these games are gathered and once an animal scores over 250 points, it reproduces. Each animal is given a limited lifespan at birth which depends upon the amount of animals. As the amount goes up, the given lifespans decrease. This “disease” avoids overcrowding by limiting the population to 600-800.

Results

This visualisation differs from the original experiments in that the games are not played in an organised structure but through random interactions. However, the results are quite similar to reports from the original scenario. The more negative strategies, “Always defect”, “Random Prober” and “Random” are always the first to go. These are usually followed by “Always cooperate” and “Adaptive”. The last three “Tit-For-Tat”, “Tit-For-Two-Tats” and “Grudger” (who always cooperate with each other regardless) tend to hold the top 3 positions in a random order.

#### 11 Responses to “Prisoner’s Dilemma Visualisation”

1. August 5, 2008 at 6:59 am

How do the movements of individuals and their assigned PD strategies interact?

It doesn’t appear to be a random walk, nor flocking/boids behavior since they all bunch up in the lower right quadrant at the end.

2. 2 jamesalliban August 5, 2008 at 6:24 pm

The movements of the objects are completely random. There are a few reasons that the all seem to buch up in the corner:

There is more interaction in groups therefore more offspring. Objects that move away from the groups interact less and produce fewer or no offspring.
If they reach the edge of the stage, they turn around. Therefore groups tend to form in corners as there are much less stragglers.

3. 3 Marc September 6, 2008 at 7:37 am

You should add ‘tit for tat with forgiveness’ and ‘win stay lose shift’

4. 4 Teddy September 6, 2008 at 2:01 pm

This is an incredible simulation!

What happens, though, if there is a degree of random mutation allowing a change in strategy…i.e. what if free riders/non-cooperators are introduced in the middle/endgame? Will some of the cooperators die out? Will a stable population be reached? Or will we get back-and-forth fluctuations of the various personalities’ populations?

5. 5 Brian September 6, 2008 at 4:49 pm

Fantastic simulation, very interesting to watch! A sort of population historical trend might make for an interesting addition.

6. 6 jamesalliban September 6, 2008 at 7:01 pm

Teddy – I haven’t experimented with adding animals at various stages. I suspect that adding more of the negative free riding animals would result in them dying off very quickly as the last few strategies would defect against them in retaliation.

Brian – Great idea. I’m always looking for ideas for data visualisation and that’s a cracker. Might have to steal that one off ya. 🙂

7. September 6, 2008 at 11:08 pm

This brings back happy memories for me cos as a kid I used to hack away on simulations like this on my BBC Micro (green screen of course) – little less sophisticated than yours though! BTW if you’re interested in this topic you should check out Evolution and the Theory of Games by Maynard-Smith.

8. 8 aurimasmb February 25, 2009 at 2:41 pm

Very impressive, I’m hoping to create a similar simulation using Flash CS4. What IDE did u use?

Any particular potential coding hurdles you encountered?

9. 9 jamesalliban February 25, 2009 at 5:40 pm

Thanks aurimasmb. I used Processing to create this. The main problem was stopping the particles from multiplying to the point where my computer melted. I put in place several techniques to eliminate this such as:

particles cannot not interact with other particles that were within a certain distance from them at birth.
If there are more that a certain amount of particles on stage at any moment, new particles have a much lower lifespan – a sort of birth defect caused by over population

There were many other techniques but I can’t remember them all now.

10. 10 Richard Dawkins April 16, 2009 at 1:33 am

Looks to me like Grudger is winning by a pretty large margin at the end there.. is that typical? Nice guys always lose?

11. 11 Richard Dawkins April 16, 2009 at 1:41 am

Actually never mind.. I see the blue bar now, I thought tit for two tats was in the teens. Great simulation!