Skip to content

Nikoleta-v3/Game-Theory-and-Python

Repository files navigation

Game-Theory-and-Python

status license PRs welcome CI

This repository was created to support a workshop on Game Theory using the programming language Python and, more specifically, the open-source Axelrod Python library.

Workshop Topics

  1. An introduction to game theory and the Iterated Prisoner's Dilemma
  2. Creating matches and tournaments using Axelrod-Python
  3. Writing strategies and contributing to Axelrod-Python
  4. Playing against strategies of the Iterated Prisoner's Dilemma

Installing Python

There are various Python distributions. We recommend using Anaconda, which comes bundled with tools like Jupyter Notebooks.

This tutorial is written using Jupyter Notebooks.

Virtual Environment

This repository includes an environment.yml file to help you set up an Anaconda environment.

To create the environment, navigate to the repository folder and run:

conda env create -f environment.yml

Activate the environment with:

conda activate game-python

You can now run notebooks in this environment. In Jupyter, go to Kernel > Change Kernel and select game-python.

Using python venv instead of Conda

If you prefer Python venv instead of Conda, you can create a virtual environment using the following commands:

python3 -m venv game-python

Then, activate the virtual environment and install the required packages:

source game-python/bin/activate
pip install -r requirements.txt

Virtual Environment in Jupyter

If your environment does not appear in Jupyter, run the following command while the environment is activated:

python -m ipykernel install --user --name=game-python

Usage

The tutorial Game Theory and Python can be used in a workshop setting or for independent learning.

Workshop

This material is designed for a 2-hour workshop. Suggested schedule:

Time Topic
0:00–0:15 Installation (see above)
0:15–0:30 Intro to game theory and the Iterated Prisoner's Dilemma
0:30–0:55 Creating matches and tournaments with Axelrod-Python
0:55–1:20 Writing strategies and contributing
1:20–1:50 Playing against IPD strategies
1:50–2:00 Closing remarks

Instructor tips:

Instructors should familiarize themselves with the content ahead of time. For each notebook, start with a short explanation or demo, then guide participants through the material. Encourage individual or group exploration of the exercises, and discuss the outcomes before moving on.

Independent Learning

If you're using this material on your own, you should aim to spend around 2 hours.

Suggested self-study timeline:

Time Topic
0:00–0:15 Installation
0:15–0:30 Intro to game theory and the Iterated Prisoner's Dilemma
0:30–1:00 Creating matches and tournaments
1:00–1:30 Writing strategies
1:30–2:00 Playing against IPD strategies

Learner tips:

Read the explanations in each notebook, run the code, and try the exercises. Reflect on the outcomes and think about what they mean in the context of game theory.

Material in Other Forms

While this tutorial was written in Jupyter Notebooks, you might prefer working with Python scripts. The notebooks have been converted to PDFs and can be found in the notebooks directory. These can serve as a guide if you wish to type everything into scripts manually.

Contributions

All contributions are welcome! This includes:

  • Suggestions for new sections
  • Bug reports
  • Code contributions

Events

This tutorial has been used in the following event:

Have you used this tutorial at an event? Let us know by contacting me or opening a pull request to add your event to this list.

License

This project is licensed under the MIT License, including all code in the notebooks listed above.

About

Game Theory and Python, a workshop investigating repeated games using the prisoner's dilemma

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 5