Skip to main content

Game Gym

MIT Licence Build Status PyPI version codecov Coverage Status

A game theory framework providing a collection of games, common API and a several game-theoretic algorithms.

The goal of the project is to provide tools for buildng complex games (e.g. board games, with partial information or simultaneous moves), computation of approximate strateges and creating artificial intelligence for such games, and to be a base for robust value learning experiments.

Under active development, looking for ideas and contributors!

Overview

Algorithms:

  • Outcome sampling MCCFR Nash equilibrium computation
  • Exact best response and exploitability
  • Approximate best response and exploitablity
  • Sparse SGD value learning (with values linear in known features)
  • Plotting strategy development (see plots for Matching Pennies, Rock-Paper-Scissors, Goofspiel(4))

Games:

  • General matrix games (normal form games), Rock-paper-scissors, Matching pennies, Prisoner's dilemma, ...
  • Goofspiel (GOPS)
  • One-card poker, Dice-poker

Game interface

For an exploration of API in Rust, see GTCogs.

To implement game you define one class derived from gamegym.Game with the following interface:

class MyRockPaperScissor(PartialInformationGame):
    ACTIONS = ("rock", "paper", "scissors")
    def __init__(self):
        # Set thenumber of players and all game actions
        super().__init__(2, self.ACTIONS)

    def initial_state(self) -> StateInfo:
        # Return node information, here player 0 is active and has all actions.
        # Note that in this simple game we do not use any game state.
        return StateInfo.new_player(state=None, player=0, actions=self.ACTIONS)

    def update_state(self, situation: Situation, action) -> StateInfo:
        # Return the node information after playing `action` in `situation`.
        if len(situation.history) == 0:
            return StateInfo.new_player(state=None, player=1, actions=self.ACTIONS)
        p1payoff = 1.0 # TODO: compute from `situation`, e.g. from `situation.history`
        return StateInfo.new_terminal(state=None, payoff=(x, -x))

# Create game instance
game = MyRockPaperScissor()
# Initial situation
s1 = game.start()
# Play some actions
s2 = game.play(s1, "rock")
s3 = s2.play("paper") # alias for game.play(s2, "paper")
# See game result
assert s3.is_terminal()
assert s3.payoff == (-1.0, 1.0)

The available base classes are PerfectInformationGame and PartialInformationGame (with specialised subclasses ObservationSequenceGame, SimultaneousGame and MatrixGame - which would be a better fit for Rock-Paper-Scissors).

The main auxiliary structs common to all games are StateInfo that contains the information about the game node itself, and Situation which additionally contains game history, accumulated payoffs, the game itself etc.

Game state is any structure the game uses to keep track of the actual game state, e.g. cards in all hands, game board state, map, ... This is not generally visible to players in partial information game, any observations are passed with observations=(p0_obs, p1_obs, public_obs) to StateInfo.

Metadata

Release files for gamegym 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gamegym 0.2.0
File Size Uploaded
gamegym-0.2.0.tar.gz 29.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gamegym 0.2.0
File Interpreter ABI Platform
gamegym-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 67.7 kB

Release files / gamegym-0.2.0.tar.gz

Download URL gamegym-0.2.0.tar.gz
Size 29.4 kB
Tags Source
SHA-256 checksum
How to use checksums
06079252e34d0b0a2f58551b6cd3130edb3c46b837837f346f8d1fa77b3cb075
BLAKE2b-256 checksum
How to use checksums
62bef89649596f05565066a48febf0f1f00e907d9aa9521b5c0b8fe7c6fc03ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.5.6

Release files / gamegym-0.2.0-py3-none-any.whl

Download URL gamegym-0.2.0-py3-none-any.whl
Size 38.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec9490d03db6c356d7fc4e32a98b41fb7d1cdc142383924ca6957594775478f7
BLAKE2b-256 checksum
How to use checksums
3fc37a4844008bf23c770fa97e1e3547a05d976f585c66de44a88d619024f9e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.5.6

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page