https://github.com/skytecat/gametheory
Simulation of a "Prisoner's Dilemma" in the Python programming language
https://github.com/skytecat/gametheory
Last synced: 11 months ago
JSON representation
Simulation of a "Prisoner's Dilemma" in the Python programming language
- Host: GitHub
- URL: https://github.com/skytecat/gametheory
- Owner: skytecat
- Created: 2024-09-18T07:06:16.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-21T06:01:17.000Z (over 1 year ago)
- Last Synced: 2025-03-03T15:47:02.588Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GameTheory
## Prisoner's Dilemma
[Описание на русском](./README_RUS.md)
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.
## Behavior types
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 |
-----
## Project Requirments
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.