This project simulates 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.
This project uses 5 models of behavior:
Behavior type | Player Actions |
---|---|
Cheater | Always cheats |
Cooperator | 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 |
Need to model a system with seven
classes - Game
, Player
and five behavior types (subclassed from Player
).
Here, registry
is used to keep track of the current number of candy
during the game, while player1
and player2
are instances of
subclasses of Player
(each being one of 5 behavior types). Calling
play()
method of a Game
instance should perform a simulation
of a specified number of matches between players of a given behavior.
Method top3()
should print current top three player's behaviors
along with their current score.
By default, code when run should simulate 10 matches (one call of
play()
) 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.