A Python-based simulation library that enables users to directly engage with Game Theory principles through several cooperation/competition games.
Project description
GameTheoryLab: Interactive Game Theory Simulation
GameTheoryLab is a Python-based simulation library that brings foundational concepts of Game Theory to life. With an intuitive interface and robust set of features, users can explore cooperative and competitive dynamics through interactive simulations of classical and custom-designed games.
The initial release focuses on the Iterated Prisoner's Dilemma (IPD), enabling players to compete against diverse strategies, simulate matches and tournaments, and even create their own strategies.
✨ Features
The axelrod_interactive subpackage houses the functionality for simulating and interacting with the IPD. The subpackage boasts of the following features:
-
Extensive Strategy Library: Includes 20 distinct IPD strategies—ranging from deterministic to stochastic, nice to nasty, forgiving to punitive, and simple to sophisticated.
-
Interactive User Mode: The
Userclass allows players to engage directly with strategies in one-on-one matches, offering hands-on insights into performance and behavior. -
Flexible Match and Tournament Engine: Simulate individual matches or full round-robin tournaments with customizable settings and detailed results.
-
CSV-Based Dataset Export: Easily export match and tournament outcomes to
.csvformat for deeper analysis.
🛠️ Installation
GameTheoryLab is easy to set up on your local machine. All you need to do is:
pip install game-theory-lab
Then, import it into your project using:
import gametheorylab
And you're all set!
🚀 Usage
Below is a simple demo illustrating how to use GameTheoryLab to explore the IPD, with the help of the axelrod_interactive subpackage:
# Demonstrating using the User class to play against strategies and saving the results
from gametheorylab import axelrod_interactive as axl
from gametheorylab.axelrod_interactive.strategies.user import User
from gametheorylab.axelrod_interactive.strategies import STRATEGIES
from gametheorylab.axelrod_interactive.arena import Arena
from random import choice, sample
# Code that sets the payoff matrix for the session. Include at the top of your script for best practices
axl.set_payoffs()
user = User("Player1")
player = choice(list(STRATEGIES.values()))()
print(player.name + ":", player.__doc__) # Information about the strategy
arena = Arena(user, player, num_rounds=20, show_results=True)
result = arena.play_round()
result.to_csv(f"user_vs_{player.__class__.__name__}") # Saving the result to a .csv file for further analysis
# Demonstrating simulating a round-robin tournament and saving the results
from gametheorylab.axelrod_interactive.tournament import Tournament
players = [s() for s in sample(list(STRATEGIES.values()), k=15)]
tournament = Tournament(players, num_repeats=5, num_rounds=250)
result = tournament.play(show_results=True) # Tournament results are displayed in the console
result.to_csv("tournament_results.csv")
🤝 Contributing
Contributions are welcome! Please follow the steps to contribute:
- Fork this repository
- Create a new branch:
git checkout -b feature-name - Commit your changes:
git commit -m 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request.
🧑💻 Author
Ayomide Olumide-Attah
Math & CS Double Major at Fisk University
📄 License
This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file game_theory_lab-0.1.3.tar.gz.
File metadata
- Download URL: game_theory_lab-0.1.3.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6923610d36e041f20553e3a789df42f1015eadb1a28ee09eb996b8213514532
|
|
| MD5 |
83960197e8bc3660ed172a6f8fbca140
|
|
| BLAKE2b-256 |
05f38dcaa8f2cfdbcd63df03b1d94e07551cede6e17f6690fedeb0f371e480c1
|
File details
Details for the file game_theory_lab-0.1.3-py3-none-any.whl.
File metadata
- Download URL: game_theory_lab-0.1.3-py3-none-any.whl
- Upload date:
- Size: 25.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65267b2d844d7ce9f7e7de02aecfc5e45095184b01500ec5027955451b99d50a
|
|
| MD5 |
d0db010bcae311126d2a3f74587b0064
|
|
| BLAKE2b-256 |
ab1eed0a350377d2a328032b2ab9b94762fcdf9ac08fcd03d1fa24e922320cb8
|