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 = 'decomposed2' players_per_group = 2 num_rounds = 1 instructions_template = 'decomposed2/instructions.html' # payoff if 1 player defects and the other cooperates""", both_A_payoff = c(100) both_B_payoff = c(113) both_C_payoff = c(126) both_D_payoff = c(137) both_E_payoff = c(150) # payoff if both players cooperate or both defect A_B_payoff = c(109) A_C_payoff = c(118) A_D_payoff = c(126) A_E_payoff = c(135) B_A_payoff = c(104) B_C_payoff = c(122) B_D_payoff = c(130) B_E_payoff = c(139) C_A_payoff = c(108) C_B_payoff = c(117) C_D_payoff = c(134) C_E_payoff = c(143) D_A_payoff = c(111) D_B_payoff = c(120) D_C_payoff = c(129) D_E_payoff = c(146) E_A_payoff = c(115) E_B_payoff = c(124) E_C_payoff = c(133) E_D_payoff = c(141) my_A_payoff = c(85) my_B_payoff = c(89) my_C_payoff = c(93) my_D_payoff = c(96) my_E_payoff = c(100) other_A_payoff = c(15) other_B_payoff = c(24) other_C_payoff = c(33) other_D_payoff = c(41) other_E_payoff = c(50) 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]