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 = 'matrix5' players_per_group = 2 num_rounds = 1 instructions_template = 'matrix5/instructions.html' # payoff if 1 player defects and the other cooperates""", both_A_payoff = c(150) both_B_payoff = c(151) both_C_payoff = c(150) both_D_payoff = c(151) both_E_payoff = c(150) # payoff if both players cooperate or both defect A_B_payoff = c(163) A_C_payoff = c(175) A_D_payoff = c(188) A_E_payoff = c(200) B_A_payoff = c(138) B_C_payoff = c(163) B_D_payoff = c(176) B_E_payoff = c(188) C_A_payoff = c(125) C_B_payoff = c(138) C_D_payoff = c(163) C_E_payoff = c(175) D_A_payoff = c(113) D_B_payoff = c(126) D_C_payoff = c(138) D_E_payoff = c(163) E_A_payoff = c(100) E_B_payoff = c(113) E_C_payoff = c(125) E_D_payoff = c(138) 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]