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 is game 2048 created with moudle of python tkinter and OOP.

Game 2048 This is game 2048 created with moudle of python tkinter and OOP. This game build on classes. For start this game run: If you have python ver

0 Nov 02, 2021
TwoDMaker (2DMaker) - Simple engine for 2D games making!

TwoDMaker (2DMaker) - Simple engine for 2D games making! Create simple games (or ui) in one hour! About. This is a simple engine for game or gui app c

Ivan Perzhinsky. 1 Jan 03, 2022
AI Mario challenges you to clear all stage of Super Mario game.

mario-ai-challenge Challenge AI Mario to clear all stages of Super Mario. GitHub Pages Site Rules Enjoy building AI Mario. Share information. Use Goog

karaage 48 Dec 10, 2022
python script to convert .OBJ files into Minecraft, rendering them in game with a core shader.

samples: random notes about the tool general output format: (animation not supported yet but planned) vertex id Minecraft's gl_VertexID isn't per mode

199 Jan 02, 2023
A simple yet powerful Snake Game made with myPygameWorkflow

snakeGame A simple yet powerful Snake Game made with myPygameWorkflow. Requirments python3 Python.org myPygameWorkflow Github Ripo Usage $ cd main $ p

DuskyElf 1 Dec 26, 2021
PLVRA is a TUI (Terminal User Interface) implementation of wordle / termo in portuguese, written in Python

PLVRA is a TUI (Terminal User Interface) implementation of wordle / termo in portuguese, written in Python

Enzo Shiraishi 1 Feb 11, 2022
Simple darts game using Tkinter and sqlite3. Also associated with Python.

Ever wanted to play a simple and fun game before, and it even keeps a database of your score? Well here it is!! Introducing; Darts! A simple and fun g

an aspirin 2 Dec 19, 2021
PyGame-Tutorial - Refrence for building games in pygame

PyGame-Tutorial How to build games using the python library PyGame End result Ho

St. Mark's Computer Science Club 2 Jan 09, 2022
An automation bot to play Myuu Discord game

Auto selfbot Myuu is a self Discordbot, meaning it will use your TOKEN to logged as your account and take commands from yourself to play the game.

6 Dec 15, 2022
Setup minecraft server (Tuinity) to your directory

hapeshiva server-setup Setup minecraft server (Tuinity) for you. Support for optimization Create optimized yml Customazible server port and view dista

3 May 11, 2022
A car learns to drive in a small 2D environment using the NEAT-Algorithm with Pygame

Self-driving-car-with-Pygame A car learns to drive in a small 2D environment using the NEAT-Algorithm with Pygame Description A car has 5 sensors ("ey

Henri 3 Feb 01, 2022
A Minecraft clone written in python and pyglet.

PyCraft A Minecraft clone written in python and pyglet. Running PyCraft To run PyCraft, run the following code: git clone https://github.com/TheWebCra

The WebCrafters 17 Dec 29, 2022
Minecraft clone using Python Ursina game engine!

Minecraft clone using Python Ursina game engine!

Taehee Lee 35 Jan 03, 2023
Quiz game made entirely with python and pygame for school work

Tabela de conteúdo Descrição Como instalar Linguagens usadas Contribuidores Créditos Problemas com o jogo? Contate-nos Descrição Quiz feito inteiramen

3 Apr 12, 2022
Racers-API - a game where you have to go around racing with your car, earning money

Racers-API About Racers API is a game where you have to go around racing with yo

3 Jan 09, 2022
Quantum version of the classical Nim game. An automatic opponent allows to game to not be as easy as it seems.

Nim game Running the game To run the program just launch : python3 game.py Rules This game is inspiring from the Nim game. You are 2 players face to f

Michaël 1 Jan 08, 2022
This repository contains the Unix Game challenges and metadata

This repository contains the Unix Game challenges and metadata

Nokia 7 Apr 06, 2022
user friendly python script who is able to catch fish in the game New World

new-world-fishing-bot release 1.1.1 click img for demonstration Download guide Click at latest release: Download and extract bot.zip: When you run fil

297 Jan 08, 2023
Adventure-Game - Adventure Game which is created using Python

Adventure Game 🌇 This is a Adventure Game which is created using Python. Featur

ArinjoyTheDev 1 Mar 19, 2022
Among AIs is a (prototype of) PC Game we developed as part of the Smart Applications course @ University of Pisa.

Among AIs is a PC Game we developed as part of the Smart Applications course @ Department of Computer Science of University of Pisa, under t

Gabriele Pisciotta 5 Dec 05, 2021