Base Game

A collection of base game classes.

Classes:
  • ExtensiveFormGame

  • NormalFormGame

class imperfecto.games.game.ExtensiveFormGame(players)[source]

Bases: abc.ABC

Abstract class for extensive form games.

In an extensive form game, players have some private information, and are unsure about the true state of the world.

Note

ExtensiveFormGame subclass must have class-level attribute actions, and n_players.

Parameters

players (Sequence[Player]) – The players of the game.

actions

The actions of the game (class-level attribute).

Type

enum.EnumMeta

n_players

The number of players in the game (class-level attribute).

Type

int

players

The players of the game.

Type

Sequence[Player]

n_players: int
actions: enum.EnumMeta
property players: Sequence[imperfecto.algos.player.Player]

The players of the game.

Return type

Sequence[Player]

abstract get_active_player(history)[source]

Get the active player of the game at the current decision point.

Parameters

history (Sequence[IntEnum]) – The history of the game.

Return type

Player

Returns

The active player of the game at the current decision point.

abstract is_terminal(history)[source]

Check if the game is in a terminal state.

Parameters

history (Sequence[IntEnum]) – The history of the game.

Return type

bool

Returns

True if the game is in a terminal state, False otherwise.

abstract get_payoffs(history)[source]

Return the payoff for each player at the current node.

Note

history must be a terminal node.

Parameters

history (Sequence[IntEnum]) – The history of the game.

Return type

Sequence[float]

Returns

The payoffs of the players at the end of the game.

abstract get_infostate(history)[source]

Return the infostate (i.e. the information set) of the game.

Parameters

history (Sequence[IntEnum]) – The history of the game.

Return type

str

Returns

A string representation of the infostate of the game.

history_to_str(history)[source]

Return a string representation of the history of the game.

Parameters

history (Sequence[IntEnum]) – The history of the game.

Return type

str

Returns

A string representation of the history of the game.

play()[source]

Play the game with the current players and their strategies and return the payoffs.

Return type

Tuple[Sequence[IntEnum], Sequence[float]]

Returns

A tuple of the play-out history of the game and the payoffs of the players.

static shorten_history(history_str)[source]

Shorten history string. Games with long action names should override this method.

Parameters

history_str (str) – history string to shorten.

Return type

str

Returns

a shortened history string.

class imperfecto.games.game.NormalFormGame(players)[source]

Bases: imperfecto.games.game.ExtensiveFormGame, abc.ABC

N-player normal form game.

This class of game is a special form of extensive-form games. A normal form game involves every player making simultaneous moves. Thus, they are unsure about each other’s move.

Parameters

players (Sequence[Player]) – The players of the game.

is_terminal(history)[source]

Check if the game is in a terminal state.

Parameters

history (Sequence[IntEnum]) – The history of the game.

Return type

bool

Returns

True if the game is in a terminal state, False otherwise.

get_infostate(history)[source]

Return the infostate (i.e. the information set) of the game.

Parameters

history (Sequence[IntEnum]) – The history of the game.

Return type

str

Returns

A string representation of the infostate of the game.

get_active_player(history)[source]

Get the active player of the game at the current decision point.

Parameters

history (Sequence[IntEnum]) – The history of the game.

Return type

Player

Returns

The active player of the game at the current decision point.