There is told about the simple game with candy, where there is a machine that controls the supply of candy for two groups of people based on whether one or both of two operators put one in it:
| Both cooperate | 1 cheats, 2 cooperates | 1 cooperates, 2 cheats | Both cheat | |
|---|---|---|---|---|
| Operator 1 | +2 candy | +3 candy | -1 candy | 0 candy |
| Operator 2 | +2 candy | -1 candy | +3 candy | 0 candy |
So, if everyone is cooperating and puts candy in a machine as agreed, everyone gets a reward. But both participants also have a temptation to cheat and only pretend to put a candy into machine, because in this case their group will get 3 candy back, just taking one candy from a second group. The problem is, if both operators decide to play dirty, then nobody will get anything.
Five models of behavior that it used to run experiments:
| Behavior type | Player Actions |
|---|---|
| Cheater | Always cheats |
| Cooperative | Always cooperates |
| Copycat | Starts with cooperating, but then just repeats whatever the other guy is doing |
| Grudger | Starts by always cooperating, but switches to Cheater forever if another guy cheats even once |
| Detective | First four times goes with [Cooperate, Cheat, Cooperate, Cooperate], and if during these four turns another guy cheats even once - switches into a Copycat. Otherwise, switches into Cheater himself |
Code simulate 10 matches between every pair of two players with different behavior types (total 10 rounds by 10 matches each, no matches between two copies of the same behavior) and print top three winners after the whole game.
The only thing a player can do on each turn is either cooperate or cheat, based on a history of a current game.