Skip to content

An implementation of iterative prisoner dilemma with reinforcement learning via q_table (NOT DQN) in Python with around 30 strategies

License

Notifications You must be signed in to change notification settings

fiore42/Prisoner-Dilemma-q_table-Python

Repository files navigation

Iterative Prisoner's Dilemma in Python

This repository contains a Python implementation of the Iterative Prisoner's Dilemma, featuring over 25 common strategies along with a reinforcement learning strategy implemented using a q_table approach (not DQN). The program is designed to simulate 9 strategies facing each other in the Prisoner's Dilemma, a standard example of a game analyzed in game theory that shows why two completely rational individuals might not cooperate, even if it appears that it is in their best interest to do so.

For more details on this project, check this Medium article

UPDATE: after I completed this project I finally had enough knowledge to firgure out the DQN approach. Check this repo.

I also added run_100.sh to collect the results over 100 repeated tournaments to check if DQN generates statistically significantly better results. It does! Check the other repo for more details.

Features

  • Multiple Strategies: Over 25 predefined strategies to simulate various scenarios in the Prisoner's Dilemma.
  • Reinforcement Learning Strategy: A strategy built using a q_table approach to reinforcement learning, providing an advanced and adaptive strategy model.
  • Strategy Selection: By default, the program randomly selects 9 strategies for each run, always including the rl_strategy. However, users have the option to specify a custom list of strategies using -a.
  • Verbose Output: Supports -v (verbose) and -vv (very verbose) flags for additional debugging and operational insights.

Getting Started

Prerequisites

Ensure you have Python installed on your machine. This code is compatible with Python 3.x.

Installation

Clone the repository to your local machine:

git clone https://github.com/fiore42/Prisoner-Dilemma-q_table-Python.git
cd Prisoner-Dilemma-q_table-Python

Usage

Run the program with the default settings:

python main.py

To select specific strategies, use the -a option followed by the strategy names:

python main.py -a strategy1 strategy2 ... strategyN

Use the verbose options for more detailed output:

# Verbose
python main.py -v

# Very Verbose
python main.py -vv

Contributing

Contributions to the project are welcome! Please feel free to submit a pull request or open an issue for bugs, suggestions, or feature requests.

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE.md file for details.

Acknowledgments

Releases

No releases published

Packages

No packages published