Types of Games

About This Package

This package deals with creating various game types.

Game definitions

Top level module for creating a Game object instance. Also abstractly defines Player, Action, and Equilibrium objects.

class games.types.game.Actions

Wrapper for an action that a Player can take.

class games.types.game.Eq(play: list)

Wrapper for an equilibrium solution for the game instance.

Parameters

play (list) – Index of action being taken.

play

Index of action being taken.

Type

list

class games.types.game.Game(players: List[games.types.game.Player])

Bare-bones game theoretical defintion of a game instance.

Parameters

players (List[Player]) – List of players defining the game interactions.

players

List of players defining the game interactions.

Type

List[Player]

actions

List of Actions object for each player.

Type

List[Actions]

N

Number of players in the game.

Type

int

eq

List of equilibrium solutions to the game.

Type

List[Eq]

U_i(i: int, play: list, *args) → Union[float, Any]

Returns utility of player i based on the play.

Parameters
  • i (int) – For returning the utility of player i.

  • play (list) – Which indexes of actions are played by each player.

  • *args – Here for extendability of the class.

Returns

Utility of player i.

Return type

Union[float, Any]

all_play(play: list) → list

Returns a list of actions based on the indexes of play taken by each player.

Parameters

play (list) – Index of each action taken by each player

Returns

A list of actions taken by each player.

Return type

list

class games.types.game.Player(name: str, index: int, actions: games.types.game.Actions)

Game theoretical based description of a player in a game.

Parameters
  • name (str) – Label for the player.

  • index (int) – Index for the player for easy reference in a list of players in a game.

  • actions (Actions) – Actions object that the player can take.

name

Label for the player.

Type

str

index

Index for the player for easy reference in a list of players in a game.

Type

int

actions

Actions object that the player can take.

Type

Actions

U(actions: list, *args) → Union[float, Any]

Utility function that should follow the von Neumann - Morgenstern axioms. Outlines preferences of own actions based on what actions othe rplayers have taken.

Parameters
  • actions (list) – List of actions that each player in the game has taken.

  • *args – Here for extendability of the class.

Raises

NotImplementedError – Needs to be implemented.

Returns

Utility of the player.

Return type

Union[float, Any]

Game Factory

Abstract definition for a factory class to create a game.

class games.types.factory.GFactory

Factory class for creating a game.

classmethod make_game(*args) → games.types.game.Game

Main method for game creation.

Parameters

*args – Arguments needed for creating a game.

Raises

NotImplementedError – Needs to be implemented.

Strategic Games

Object definitions for a strategic normal form game directly through payoff matrices. Includes factory methods for normal form game creation.

class games.types.strategic.StrategicFactory

Factory class for creating a normal form game from a list of payoff matrices.

classmethod make_game(payoffs: List[numpy.ndarray]) → games.types.strategic.StrategicGame

Main method for game creation

Parameters

payoffs (List[np.ndarray]) – Payoff matrix for each player. Shape matches the number of actions for each player.

Returns

Strategic Normal Form Game.

Return type

StrategicGame

class games.types.strategic.StrategicGame(players: List[games.types.strategic.StrategicPlayer])

Strategic Normal Form Game.

Parameters

players (List[StrategicPlayer]) – List of players in the game.

payoffs

List of the payoff matrices for the defined game.

Type

List[np.ndarray]

class games.types.strategic.StrategicPlayer(name: str, index: int, actions: games.types.misc.FActions, payoff: numpy.ndarray)

Player in a normal form game.

Parameters
  • name (str) – Label for the player.

  • index (int) – Index for the player for easy reference in a list of players in a game.

  • actions (FActions) – Actions object that the player can take.

  • payoff (np.ndarray) – Payoff matrix determining the utility function.

payoff

Payoff matrix determining the utility function.

Type

np.ndarray

U(actions: List[int]) → float

Utility function based on a predefined payoff matrix.

Parameters

actions (List[int]) – List of actions that each player in the game has taken.

Returns

Utility of the player.

Return type

float

Congestion Games

Module for creating a Congestion Game with relevant player definitions.

class games.types.congestion.CongestionFactory

Factory class for creating a congestion game based on given parameters.

classmethod make_game(all_actions: List[List[List[int]]], r_m: int, list_f_r: List[Callable[[int, List[int]], float]]) → games.types.congestion.CongestionGame

Main method for game creation

Parameters
  • all_actions (List[List[List[int]]]) – List of possible coverings for each player.

  • r_m (int) – Number of resources in the congestion game.

  • list_f_r (List[Callable[[int, List[int]], float]]) – List of covering utility functions for each player.

Returns

Created congestion game.

Return type

CongestionGame

class games.types.congestion.CongestionGame(players: List[games.types.congestion.CongestionPlayer], r_m: int)

General Congestion Game with player and resource dependent covering functions.

Parameters
  • players (List[StrategicPlayer]) – List of players in the game.

  • r_m (int) – number of resources in the congestion game.

r_m

number of resources in the congestion game.

Type

int

pcover(actions: List[List[int]]) → List[Tuple[int, List[int]]]

Gives what players are covering which resource over a given action set.

Parameters

actions (List[List[int]]) – Covering action taken by all players.

Returns

List of (resource index, which players are covering resource).

Return type

List[Tuple[int, List[int]]]

class games.types.congestion.CongestionPlayer(name: str, index: int, actions: games.types.misc.FActions)

A player in a congestion game.

Parameters
  • name (str) – Label for the player.

  • index (int) – Index for the player for easy reference in a list of players in a game.

  • actions (FActions) – Actions object that the player can take. Action is subset of power set of {1, …, number of resources}.

U(actions: List[List[int]]) → float

Utility function that should follow the von Neumann - Morgenstern axioms. Outlines preferences of own actions based on what actions othe rplayers have taken.

Parameters

actions (list) – List of actions that each player in the game has taken.

Returns

Utility of the player.

Return type

Union[float, Any]

f_r(r: int, players: List[int]) → float

Utility given if covering the resource r when others are covering the resource as well.

Parameters
  • r (int) – Which resource under consideration.

  • players (List[int]) – Players including self that are covering resource r.

Raises

NotImplementedError – Needs to be implemented.

Returns

Utility gained from the covering that resource.

Return type

float

pcover(actions: List[List[int]]) → List[Tuple[int, List[int]]]

Gives which players are covering resource r covered by self.

Parameters

actions (List[List[int]]) – Covering action taken by all players.

Returns

List of (resource index, which players are covering resource, including self).

Return type

List[Tuple[int, List[int]]]

class games.types.congestion.MutableCGPlayer(name: str, index: int, actions: games.types.misc.FActions, f_r: Callable[[int, List[int]], float])

Congestion Player with modifiable covering function f_r

Parameters
  • name (str) – Label for the player.

  • index (int) – Index for the player for easy reference in a list of players in a game.

  • actions (Actions) – Actions object that the player can take.

  • f_r (Callable[[int, List[int]], float]) – Given utility covering function.

f_r(r: int, players: List[int]) → float

Utility given if covering the resource r when others are covering the resource as well.

Parameters
  • r (int) – Which resource under consideration.

  • players (List[int]) – Players including self that are covering resource r.

Returns

Utility gained from the covering that resource.

Return type

float

Board Games

class games.types.boardgame.BGFactory
class games.types.boardgame.BoardGame(players, board)
U_i(i, play, *args)

Returns utility of player i based on the play.

Parameters
  • i (int) – For returning the utility of player i.

  • play (list) – Which indexes of actions are played by each player.

  • *args – Here for extendability of the class.

Returns

Utility of player i.

Return type

Union[float, Any]

class games.types.boardgame.BoardPlayer(name, index, actions)
U(play, board, *args)

Utility function that should follow the von Neumann - Morgenstern axioms. Outlines preferences of own actions based on what actions othe rplayers have taken.

Parameters
  • actions (list) – List of actions that each player in the game has taken.

  • *args – Here for extendability of the class.

Raises

NotImplementedError – Needs to be implemented.

Returns

Utility of the player.

Return type

Union[float, Any]

Equilibrium Definitions

Parent classes for types of equilibrium

class games.types.equilibrium.CoarseEq(play)

Coarse Correlated Equilibrium.

class games.types.equilibrium.CorEq(play)

Correlated Equilibrium.

class games.types.equilibrium.DomEq(play)

Strictly Dominating Equilibrium

class games.types.equilibrium.MixedEq(play)

Mixed Nash equilibrium.

class games.types.equilibrium.PureEq(play)

Pure Nash Equilibrium.

Distributed Resource Games

class games.types.resource.ResourceFactory
classmethod make_game(all_actions: List[List[List[int]]], values: List[float], f: List[float]) → games.types.resource.ResourceGame

Main method for game creation.

Parameters

*args – Arguments needed for creating a game.

Raises

NotImplementedError – Needs to be implemented.

class games.types.resource.ResourceGame(players: List[games.types.congestion.CongestionPlayer], values: List[float], f: List[float])
class games.types.resource.ResourcePlayer(name: str, index: int, actions: games.types.misc.FActions, f: List[float], values: List[float])
f_r(r: int, players: List[int]) → float

Utility given if covering the resource r when others are covering the resource as well.

Parameters
  • r (int) – Which resource under consideration.

  • players (List[int]) – Players including self that are covering resource r.

Raises

NotImplementedError – Needs to be implemented.

Returns

Utility gained from the covering that resource.

Return type

float

State Based Games

class games.types.stategame.StatePlayer(name, index, actions, state)

Miscellaneous

Miscellaneous class definitions and functions that are useful for creating games.

class games.types.misc.FActions(actions: list)

Wrapper for a finite action set using a list.

Parameters

actions (list) – Available actions to a player.

actions

Available actions to a player.

Type

list

class games.types.misc.MutablePlayer(name: str, index: int, actions: games.types.game.Actions, util: Callable[[...], Union[float, Any]])

Player with utility function as a object parameter.

Parameters
  • name (str) – Label for the player.

  • index (int) – Index for the player for easy reference in a list of players in a game.

  • actions (Actions) – Actions object that the player can take.

  • util (Callable[.., Union[float, Any]]) – Prescribed utility function for the player.

U(actions: list, *args) → Union[float, Any]

Utility function that should follow the von Neumann - Morgenstern axioms. Outlines preferences of own actions based on what actions othe rplayers have taken.

Parameters
  • actions (list) – List of actions that each player in the game has taken.

  • *args – Here for extendability of the class.

Returns

Utility of the player.

Return type

Union[float, Any]

class games.types.misc.PotentialGame(players: List[games.types.game.Player])

Potential Game endowed with a potential function.

Parameters

players (List[Player]) – List of players defining the game interactions.

potential(play: list, *args) → float

Potential function.

Parameters
  • play (list) – Which indexes of actions are played by each player.

  • *args – Here for extendability of the class.

Returns

Potential of the game.

Return type

float

Raises

NotImplementedError – Needs to be implemented.

class games.types.misc.WelfareGame(players: List[games.types.game.Player])

Game endowed with a system welfare function. Convention is larger welfare is better.

Parameters

players (List[Player]) – List of players defining the game interactions.

welfare(play: list, *args) → Union[float, Any]

Welfare function.

Parameters
  • play (list) – Which indexes of actions are played by each player.

  • *args – Here for extendability of the class.

Returns

Welfare of the system.

Return type

Union[float, Any]

Raises

NotImplementedError – Needs to be implemented.

Indices and tables