2P Prisoners Dilemma

Ver. 1.0.2 (2024-01-27)

This module provides a 2-player game of Prisoners’ Dilemma with random solver. In the near future, we are going to add more solvers and this howto is going to be updated accordingly.

The game consists of two competitors, where each competitor represents a prisonner. Both of them have a goal to minimize their prison sentences, where their length of sentences depend on their decision in front of the jury.

If a prisoner pleads guilty, while another prisoner pleads not guilty. The guilty prisoner gets 8 years of imprisonment, while the not guilty prisoner gets 1 year of imprisonment.

If both of them plead guilty, then each of them gets 2 years of imprisonment.

Meanwhile, if both of them plead not guilty, then each of them obtains 5 years of imprisonment.

To be noted, the decision making of the prisoners take place simultaneously, where: - Decision “0” means confess - Decision “1” means not confess

class mlpro.gt.pool.native.games.prisonersdilemma_2p.PayoffFunction_PD2P(p_func_type: int, p_dim_elems: list = None, p_num_coalisions: int = None, p_logging=True)

Bases: GTFunction

_setup_mapping_matrix() ndarray

A method to setup the mapping of the payoff matrix between strategies and payoffs. This is only applicable for C_FUNC_PAYOFF_MATRIX. This method needs to be redefined based on the setup of the game.

Returns:

Resulted mapping.

Return type:

np.ndarray

_setup_payoff_matrix()

A method to setup payoff matrices. This is only applicable for C_FUNC_PAYOFF_MATRIX. This method needs to be redefined based on the setup of the game.

class mlpro.gt.pool.native.games.prisonersdilemma_2p.PrisonersDilemma2PGame(p_mode=0, p_ada=False, p_cycle_limit=1, p_visualize: bool = False, p_logging=True)

Bases: GTGame

C_NAME = 'PrisonersDilemma2PGame'
_setup(p_mode, p_ada: bool, p_visualize: bool, p_logging) Model

Custom setup of GT Game. Payoff matrix has to be defined here as self._payoff.

Parameters:
  • p_mode – Operation mode. See Mode.C_VALID_MODES for valid values. Default = Mode.C_MODE_SIM

  • p_ada (bool) – Boolean switch for adaptivity.

  • p_visualize (bool) – Boolean switch for visualisation.

  • p_logging – Log level (see constants of class Log).

Returns:

player – GTPlayer model (object of type GTPlayer, GTCoalition or GTCompetition).

Return type:

GTPlayer