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.
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.