from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '\nThis is a one-shot "Prisoner\'s Dilemma". Two players are asked separately\nwhether they want to cooperate or defect. Their choices directly determine the\npayoffs.\n' class Constants(BaseConstants): name_in_url = 'OneShot_PD_BEB' players_per_group = 2 num_rounds = 2 betray_payoff = c(112) betrayed_payoff = c(25) both_cooperate_payoff = c(73) both_defect_payoff = c(42) expected_cooperators = 12 expected_cooperators2 = 8 bonus = c(40) instructions_template = 'OneShot_PD_BEB/instructions.html' mywaitpage_template = 'OneShot_PD_BEB/mywaitpage.html' class Subsession(BaseSubsession): def Grouping_random(self): self.group_randomly() 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']], doc='This player s decision', widget=widgets.RadioSelect) beliefs = models.IntegerField(choices=[[0, '0'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, '10'], [11, '11'], [12, '12'], [13, '13'], [14, '14'], [15, '15'], [16, '16'], [17, '17'], [18, '18'], [19, '19'], [20, '20']], label='You believe:') def other_player(self): return self.get_others_in_group()[0] def set_payoff(self): payoff_matrix = dict( A=dict( A=Constants.both_cooperate_payoff, B=Constants.betrayed_payoff, ), B=dict( A=Constants.betray_payoff, B=Constants.both_defect_payoff, ), ) if self.in_round(1).beliefs == Constants.expected_cooperators: payoff_bonus = Constants.bonus else: payoff_bonus = 0 if self.in_round(2).beliefs == Constants.expected_cooperators2: payoff_bonuss = Constants.bonus else: payoff_bonuss = 0 self.payoff = payoff_matrix[self.in_round(1).decision][self.in_round(1).other_player().decision] + payoff_matrix[self.in_round(2).decision][self.in_round(2).other_player().decision] + payoff_bonus + payoff_bonuss