from otree.api import * import random doc = """ Dierolling task, Akdeniz & Mathew, 2022, Normative versus prosocial underpinnings of human decision making. """ class Constants(BaseConstants): name_in_url = 'part3dierolling' players_per_group = None num_rounds = 3 lying_reward_die_roll = cu(500) # payoff for die roll for the paying number no_lying_reward_die_roll = cu(0) # payoff for die roll for any other number task = 1 class Subsession(BaseSubsession): def creating_session(self): print('in creating_session', self.round_number) for p in self.get_players(): p.actual_roll = random.randint(1, 6) print('set the actual roll for player', p.id_in_subsession, 'and round', self.round_number, 'to', p.actual_roll) class Group(BaseGroup): pass class Player(BasePlayer): q1 = models.IntegerField(initial=None, label="") q2 = models.IntegerField(initial=None, label="") q3 = models.IntegerField(initial=None, label="") q4 = models.IntegerField(initial=None, label="") q5 = models.IntegerField(initial=None, label="") q6 = models.IntegerField(initial=None, label="") truthful = models.IntegerField() report = models.IntegerField() room_for_lying = models.IntegerField() lying_behavior = models.FloatField() reported_roll = models.IntegerField(min=1, max=6, label="The outcome of the die roll was", doc="""reported roll""") actual_roll = models.IntegerField(min=1, max=6, label="", doc="""actual roll""") round = models.IntegerField() choice_dieroll = models.IntegerField() payment_dieroll = models.CurrencyField() choice_roll = models.IntegerField() payment_roll = models.CurrencyField() chosen_round = models.IntegerField() def set_payoffs(self): print('in set_payoffs') if self.reported_roll == 5: self.payoff = Constants.lying_reward_die_roll self.report = 1 else: self.payoff = Constants.no_lying_reward_die_roll self.report = 0 if self.actual_roll == 5: self.truthful = 1 else: self.truthful = 0 def set_results_dieroll(self): print('in set_results') self.room_for_lying = Constants.num_rounds - sum([p.truthful for p in self.in_all_rounds()]) self.lying_behavior = ( sum([p.report for p in self.in_all_rounds()]) - sum([p.truthful for p in self.in_all_rounds()])) print("The room for lying for", self.id_in_subsession, 'was', self.room_for_lying) print("The lying behavior of", self.id_in_subsession, 'was', self.lying_behavior) self.round = random.choice([1, 2, 3]) print('chosen round', self.round) chosen_player = self.in_round(self.round) print('chosen player', chosen_player) # participant = self.in_round(self.round) # self.chosen_round = self.round print('chosen round', self.round) self.choice_dieroll = chosen_player.reported_roll print('choice', self.choice_dieroll) if chosen_player.reported_roll == 5: self.payment_dieroll = Constants.lying_reward_die_roll else: self.payment_dieroll = Constants.no_lying_reward_die_roll print('payoff', self.payment_dieroll) participant = self.participant participant.choice_roll = self.choice_dieroll participant.payment_roll = self.payment_dieroll participant.chosen_round = self.round print(participant.payment_roll, participant.choice_roll, participant.chosen_round)