To cooperate of defect (besides of coding): Prisoners dilemma, a game theory example in R
R-bloggers 2014-08-11
Summary:
Hello Computer Science and/or R enthusiasts. This week I had the opportunity to try something that was in my To-Do list a while ago. The idea came almost instantly after reading Dr. Richard Dawkins book, The Selfish Gene (which was a BD gift, thanks Andy). I feel the obligated necessity to program my own implementation of the prisoners dilemma and make my own version of the contest. To try different parameters of greediness and vindictiveness, just coding in the name of science. You can download the code here *****************INTRODUCTION***************** Here's a basic definition of prisoners dilemma that can be found in this Wikipedia article: The structure of the traditional Prisoners’ Dilemma can be generalized from its original prisoner setting. Suppose that the two players are represented by the colors, red and blue, and that each player chooses to either "Cooperate" or "Defect". If both players cooperate, they both receive the reward, R, for cooperating. If Blue defects while Red cooperates, then Blue receives the temptation, T payoff while Red receives the "sucker's", S, payoff. Similarly, if Blue cooperates while Red defects, then Blue receives the sucker's payoff S while Red receives the temptation payoff T. If both players defect, they both receive the punishment payoff P. And to be a prisoner's dilemma game in the strong sense, the following condition must hold for the payoffs: T > R > P > S *****************MATERIALS***************** I decided to program three basic strategy functions:
- tit.for.tat.bot: this simple strategy repeats opponent's last choice
- This bot/strategy is parameter-free
- greedy.bot: this strategy is affected by the parameter of greedy.level, which increases the probability of the bot to "defect" when this parameter is close to 1.0. If this parameter is set to 0.5, then the bot will choose randomly.
- This bot does not care about the previous action of the other player, it only decides to "defect" or "cooperate" based on its own greediness.
- vindictive.bot: this strategy is affected by the parameter of vindictive.level, which is only used when the previous action of the other player is "defect" in the same sense as the greedy.level affects the greedy.bot, otherwise it will "cooperate".
- This means that if the other player plays "cooperate", this bot will "cooperate" too, but at any moment when the other player plays "defect", this bot will trigger its own vindictive.level to decide if it will play "defect" or to "cooperate".
- All bots have three parameters as arguments:
- action: last action of the other player
- greedy.level*
- vindictive.level
- *The greedy.level parameter in the tit.for.tat.bot and the vindictive.bot is only used when this bots are playing as player.1 and have to decide the first action/move against player.2. After that event, this parameter is no longer used for these bots.
- Each point in the plots means 1000 (iter=1000) plays of player.1 vs player.2
- Parameters for the payoff matrix: T=20, R=5, P=1 and S=0
- Try different pairwise comparisons of strategies varying the greediness and the vindictiveness of the bots
- Make our clandestine fight club with the bots (1st RULE: You do not code about FIGHT CLUB)