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 = 'decomposed6' players_per_group = 2 num_rounds = 1 instructions_template = 'decomposed6/instructions.html' # payoff if 1 player defects and the other cooperates""", both_A_payoff = c(150) both_B_payoff = c(155) both_C_payoff = c(161) both_D_payoff = c(165) both_E_payoff = c(170) # payoff if both players cooperate or both defect A_B_payoff = c(159) A_C_payoff = c(168) A_D_payoff = c(176) A_E_payoff = c(185) B_A_payoff = c(146) B_C_payoff = c(164) B_D_payoff = c(172) B_E_payoff = c(181) C_A_payoff = c(143) C_B_payoff = c(152) C_D_payoff = c(169) C_E_payoff = c(178) D_A_payoff = c(139) D_B_payoff = c(148) D_C_payoff = c(157) D_E_payoff = c(174) E_A_payoff = c(135) E_B_payoff = c(144) E_C_payoff = c(153) E_D_payoff = c(161) my_A_payoff = c(100) my_B_payoff = c(96) my_C_payoff = c(93) my_D_payoff = c(89) my_E_payoff = c(85) other_A_payoff = c(50) other_B_payoff = c(59) other_C_payoff = c(68) other_D_payoff = c(76) other_E_payoff = c(85) 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]