An algorithm to reach a correlated equilibrium in multiplayer games.

Overview

build Documentation Status Downloads Codacy Badge codecov GitHub contributors Games

Correlatedpy: a python library for distributed learning of correlated equilibrium in multiplayer strategic games.

View Demo · Report Bug · Request Feature

The library implements a distributed learning algorithm allowing players to converge towards a correlated equilibrium point.

Installation

Correlatedpy has a small set of Python dependencies. It is straightforward to install on all operating systems as it only requires the following python packages

$ python -m pip install correlatedpy

To install Correlatepy on Fedora, use:

$ dnf install python3-correlatepy

The Environment

Parameters

The game has three global parameters that are shared accross all instances of all classes of the game. They can be initialized as follows

history = [(0,0)] # history of action profiles played by players
epsilon = 0.02 # exploration rate
alpha = 0.01 # targetted approximate correlated equilibrium

Players

the Player class has the attributes we list below:

  • number: object instance unique identifier
  • payoff: player's payoff matrix
  • state: player's state ('syn' or 'asyn')
  • history: game history
  • epsilon: exploration rate
  • alpha: approximate correlated alpha-equilibrium

We can now create the players by setting a value for each one of the parameters.

P1 = Player(number = 1, payoff = np.array([[0, 0], [1, -1]]), state = 'asyn', history = [(0, 0)], epsilon = 0.02, alpha = 0.01)
P2 = Player(number = 2, payoff = np.array([[0, 0], [-1, 1]]), state = 'asyn', history = [(0, 0)], epsilon = 0.02, alpha = 0.01)

Game

After creating players, we can now instanciate a game, define how many rounds to play, and add the players to it.

G = Game(iterations = 100000, history = [(0, 0)], epsilon = 0.02, alpha=0.01)

G.add_player(P1)
G.add_player(P2)

Learning

The game is played repeatedly by calling the instance method run().

G.run()

Simulation Results

G.results()

Diagram

Examples of Games

See the documentation for some examples and notebooks.

Chicken Game

This game has two pure Nash equilibria and one mixed Nash equilibrium.

  D C
D 0,0 7,2
C 2,7 6,6

We show the evolution of the probabilities of play of each profile.

Rock-Paper-Scissors

This game has a unique mixed Nash equilibrium point.

  R P S
R 0,0 -1,1 1,-1
P 1,-1 0,0 -1,1
S -1,1 1,-1 0,0

The simulation results show the probability of play of each profile.

A 3x2 game

This game has two mixed Nash equilibria.

  X Y
A 2,29 16,7
B 4,7 6,13
C 4,4 6,6

We show the empirical distribution of play of each profile.

three-player game

X Y
  C D
A 0,0,0 0,0,0
B 0,0,0 0,0,0
  C D
A 0,0,0 0,0,0
B 0,0,0 0,0,0

Usage

Payoff matrices

For an n-player game with action spaces of size , creating the payoff matrice for player i is performed in the following manner:

>>> import correlatedpy as correlated
>>> A = [[1, 2], [3, 0]]
>>> B = [[0, 2], [3, 1]]
>>> game = correlated.Game(A, B)
>>> for eq in game.support_enumeration():
...     print(eq)
(array([1., 0.]), array([0., 1.]))
(array([0., 1.]), array([1., 0.]))
(array([0.5, 0.5]), array([0.5, 0.5]))
>>> game[[0, 1], [1, 0]]
array([3, 3])

Documentation

Full documentation is available here: http://correlatedpy.readthedocs.io/

Citing

If you use the project in your work, please consider citing it with:

@misc{correlatedpy,
  author = {Boufous, Omar},
  title = {Correlatedpy: a python library for distributed learning of correlated equilibrium in multiplayer strategic games.},
  year = {2021},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/oboufous/correlatedpy}},
}

Other game theoretic software

  • Nashpy is a python library for the computation of equilibria of 2 player strategic games.
  • Gambit is a library with a python api and support for more algorithms and more than 2 player games.
  • Game theory explorer is a web interface to gambit useful for teaching.
  • Axelrod is a research library aimed at the study of the Iterated Prisoners dilemma.

Development

Clone the repository and create a virtual environment:

$ git clone https://github.com/oboufous/correlatedpy.git
$ cd correlatedpy
$ python -m venv env

Activate the virtual environment and install tox:

$ source env/bin/activate
$ python -m pip install tox

Make modifications.

To run the tests:

$ python -m tox

To build the documentation. First install the software which also installs the documentation build requirements.

$ python -m pip install flit
$ python -m flit install --symlink

Then:

$ cd docs
$ make html

Full contribution documentation is available at https://correlatedpy.readthedocs.io/en/latest/contributing/index.html

Pull requests are welcome.

Code of conduct

In the interest of fostering an open and welcoming environment, all contributors, maintainers and users are expected to abide by the Python code of conduct: https://www.python.org/psf/codeofconduct/

Owner
Omar Boufous
Research Scientist
Omar Boufous
This repository contains algorithm and solver for the game WORDLE

Wordle-Cracker This repository contains algorithm and solver for the game WORDLE How to use Run the program: python main.py Type in the guess word in

YiHsin Chen 3 May 14, 2022
Python Interactive Mini Games

Python Interactive Mini Games Mini projects from Coursera's An Introduction to I

Ashish Choudhary 1 Jan 16, 2022
Jogo Flappy Bird com phyton e phygame

Flappy-Bird Tecnologias usadas Requisitos para inicializar o jogo: Python faça o download em: https://www.python.org/ Pygame faça o download em: https

João Guilherme 1 Dec 06, 2021
Multiple hacks that breaks the game

Blooket-Hack All of the cheats are based on a game mode.

glizzz_y 484 Feb 25, 2022
Pyvidplayer - An extremely easy to use module that plays videos on Pygame

pyvidplayer An extremely easy to use module that plays videos on Pygame Example

17 Dec 05, 2022
Code for an arcade pop-a-shot style basketball game on Raspberry Pi

Basketball-Game Code for an arcade pop-a-shot style basketball game on Raspberry Pi, made over the course of winter break 2022. How To Run: Running th

Seth Reis 1 Jan 21, 2022
This is the card game like HearthStone and Magic

Territory War How to use it use pip3 to install django and channels: pip3 install Django pip3 install channels go to CardGame/first/consumers.py and g

Caesar 3 Oct 24, 2022
Wordle-Python - A simple low-key clone of the popular game WORDLE made with python and a 2D Graphics module Pygame

Wordle-Python A simple low-key clone of the popular game WORDLE made with python

Showmick Kar 7 Feb 10, 2022
Flappy Bird hack using Deep Reinforcement Learning (Deep Q-learning).

Using Deep Q-Network to Learn How To Play Flappy Bird 7 mins version: DQN for flappy bird Overview This project follows the description of the Deep Q

Yen-Chen Lin 6.4k Dec 30, 2022
This is an interactive MiniMap made with Python, PyQT5 & Pytesseract for the game

NWMM-New-World-MiniMap Features: Automatically grabs position from "New World" Instance Live visualisation of player position on MiniMap Circular & re

Nezzquikk 18 Sep 21, 2022
Tic Tac Toe Game build with Python

Tic Tac Toe Game Description two players who take turns marking the spaces in a three-by-three grid with X or O. The player who succeeds in placing th

Kemal Kochekov 2 Jan 21, 2022
Software Design | Spring 2020 | Classic Arcade Game

Breakout Software Design Final Project, Spring 2020 Team members: Izumi, Lilo For our Interactive Visualization, we implemented the classic arcade gam

Lilo Heinrich 1 Jul 26, 2022
Mandaw 2 Mar 01, 2022
3 Oct 22, 2021
Hagia is a 2D game engine and toolset for Python.

HAGIA What is Hagia? Hagia is a 2D game engine and toolset for Python. Hagia has

star 3 Jun 01, 2022
Python desktop application to create, distribute, discover, and run codegames

Python desktop application to create, distribute, discover, and run codegames

2 Nov 16, 2021
This a Chess PGN saver which allows you to save your game pgns, in a .pgn file

PGN Saver This a Chess PGN saver which allows you to save your game pgns, in a .pgn file This can be a very useful tool for the people using chessbase

3 Jan 06, 2022
Typing Game : from nob to good

Fast and Curious A game to learn/improve keyboard typing skills. The main idea is to improve your typing skills and at the same time learn fun facts (

Raffaele Fiorillo 7 Jun 13, 2022
Lint game data metafiles against GTA5.xsd for Rockstar's game engine (RAGE)

rage-lint Lint RAGE (only GTA5 at the moment) meta/XML files for validity based off of the GTA5.xsd generated from game code. This script accepts a se

GoatGeek 11 Sep 18, 2022
Creating Tetris with Pygame

Tetris 🤝 Contributing Contributions, issues and feature requests are welcome! Feel free to check issues page. Show your support Give a ⭐️ if this pro

Gavin Capriola 0 Mar 01, 2022