from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ This is a one-shot "Prisoner's Dilemma". Two players are asked separately whether they want to cooperate or defect. Their choices directly determine the payoffs. """ class Constants(BaseConstants): name_in_url = 'matrix1' players_per_group = 2 num_rounds = 1 instructions_template = 'matrix1/instructions.html' # payoff if 1 player defects and the other cooperates""", both_A_payoff = c(170) both_B_payoff = c(153) both_C_payoff = c(135) both_D_payoff = c(118) both_E_payoff = c(100) # payoff if both players cooperate or both defect A_B_payoff = c(153) A_C_payoff = c(135) A_D_payoff = c(118) A_E_payoff = c(100) B_A_payoff = c(170) B_C_payoff = c(135) B_D_payoff = c(118) B_E_payoff = c(100) C_A_payoff = c(170) C_B_payoff = c(153) C_D_payoff = c(118) C_E_payoff = c(100) D_A_payoff = c(170) D_B_payoff = c(153) D_C_payoff = c(135) D_E_payoff = c(100) E_A_payoff = c(170) E_B_payoff = c(153) E_C_payoff = c(135) E_D_payoff = c(118) class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_payoffs(self): for p in self.get_players(): p.set_payoff() class Player(BasePlayer): decision = models.StringField( choices=[['A', 'A'], ['B', 'B'], ['C', 'C'], ['D', 'D'], ['E', 'E']], doc="""This player's decision""", widget=widgets.RadioSelect, ) def other_player(self): return self.get_others_in_group()[0] def set_payoff(self): payoff_matrix = dict( A=dict( A=Constants.both_A_payoff, B=Constants.A_B_payoff, C=Constants.A_C_payoff, D=Constants.A_D_payoff, E=Constants.A_E_payoff, ), B=dict( B=Constants.both_B_payoff, A=Constants.B_A_payoff, C=Constants.B_C_payoff, D=Constants.B_D_payoff, E=Constants.B_E_payoff, ), C=dict( C=Constants.both_C_payoff, B=Constants.C_B_payoff, A=Constants.C_A_payoff, D=Constants.C_D_payoff, E=Constants.C_E_payoff, ), D=dict( D=Constants.both_D_payoff, B=Constants.D_B_payoff, C=Constants.D_C_payoff, A=Constants.D_A_payoff, E=Constants.D_E_payoff, ), E=dict( E=Constants.both_E_payoff, B=Constants.E_B_payoff, C=Constants.E_C_payoff, D=Constants.E_D_payoff, A=Constants.E_A_payoff, ), ) self.payoff = payoff_matrix[self.decision][self.other_player().decision]