from otree.api import * doc = """ One player decides how much to take from or give to another. A third player decides how much to punish the dictator, depending on the dictator's decision. Akdeniz & Mathew, 2022, Normative versus prosocial underpinnings of human decision making. """ class Constants(BaseConstants): name_in_url = 'part1task2j_1' players_per_group = None num_rounds = 1 endowment_dictator = 250 endowment_punisher = 100 rate_punishment = 5 sit = 2 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): dg_amount_j_give = models.IntegerField( label='How many points do you want to give to citizen 2?', min=0, max=Constants.endowment_dictator, ) dg_amount_j_steal = models.IntegerField( label='How many points do you want to steal from citizen 2?', min=0, max=Constants.endowment_dictator, ) dg_take_j = models.IntegerField( choices=[[0, 'I want to give points to citizen 2.'], [1, 'I do not want to give points to or steal points from citizen 2.'], [2, 'I want to steal points from citizen 2.']], label='What would you like to do?', widget=widgets.RadioSelect, ) ex1 = models.CurrencyField( doc="""Answer to first example""", min=0, max=2*Constants.endowment_dictator, label="", ) ex2 = models.CurrencyField( doc="""Answer to second example""", min=0, max=2*Constants.endowment_dictator, label="", ) ex3 = models.CurrencyField( doc="""Answer to third example""", min=0, max=Constants.endowment_dictator, label="", ) ex4 = models.CurrencyField( doc="""Answer to fourth example""", min=0, max=Constants.endowment_punisher, label="", ) punishment1j = models.IntegerField(min=0, label='citizen 1 stole 250 points from citizen 2.') punishment2j = models.IntegerField(min=0, label='citizen 1 stole 200 points from citizen 2.') punishment3j = models.IntegerField(min=0, label='citizen 1 stole 150 points from citizen 2.') punishment4j = models.IntegerField(min=0, label='citizen 1 stole 100 points from citizen 2.') punishment5j = models.IntegerField(min=0, label='citizen 1 stole 50 points from citizen 2.') punishment6j = models.IntegerField(min=0, label='citizen 1 did not steal points from or give points to citizen 2.') punishment7j = models.IntegerField(min=0, label='citizen 1 gave 50 points to citizen 2.') punishment8j = models.IntegerField(min=0, label='citizen 1 gave 100 points to citizen 2.') punishment9j = models.IntegerField(min=0, label='citizen 1 gave 150 points to citizen 2.') punishment10j = models.IntegerField(min=0, label='citizen 1 gave 200 points to citizen 2.') # PAGES class Start(Page): pass class Instructions(Page): form_model = 'player' form_fields = ['ex1', 'ex2', 'ex3', 'ex4'] def error_message(self, value): if value["ex1"] != 240: return 'The first question is not answered correctly. Consult the instructions and try again.' elif value["ex2"] != 200: return 'The second question is not answered correctly. Consult the instructions and try again.' elif value["ex3"] != 88: return 'The third question is not answered correctly. Consult the instructions and try again.' elif value["ex4"] != 70: return 'The fourth question is not answered correctly. Consult the instructions and try again.' class StartTask(Page): pass class Round1(Page): form_model = 'player' form_fields = ['dg_take_j'] class Round1Amount(Page): form_model = 'player' @staticmethod def get_form_fields(self): if self.dg_take_j == 0: return ['dg_amount_j_give'] elif self.dg_take_j == 2: return ['dg_amount_j_steal'] def error_message(self, value): if (self.dg_take_j == 0) and (value["dg_amount_j_give"] % 50 != 0): return 'You can only give points in a multiple of 50 (0, 50, 100, 150, 200, or 250 points).' elif (self.dg_take_j == 2) and (value["dg_amount_j_steal"] % 50 != 0): return 'You can only steal points in a multiple of 50 (0, 50, 100, 150, 200, or 250 points).' def is_displayed(player: Player): return player.dg_take_j != 1 # class Round1(Page): # form_model = 'player' # form_fields = ['dg_take_j', 'dg_amount_j'] # # def error_message(self, value): # if value["dg_amount_j"] % 50 != 0: # return 'You can only steal or give points in a multiple of 50 (0, 50, 100, 150, 200, or 250 points).' # class Round2(Page): pass class Round3(Page): form_model = 'player' form_fields = ['punishment1j', 'punishment2j', 'punishment3j', 'punishment4j', 'punishment5j', 'punishment6j', 'punishment7j', 'punishment8j', 'punishment9j', 'punishment10j'] def error_message(self, value): if value["punishment1j"] > 100: return 'You can charge penalty points up to the point where the remaining earnings of citizen 1 become zero.' elif value["punishment2j"] > 90: return 'You can charge penalty points up to the point where the remaining earnings of citizen 1 become zero.' elif value["punishment3j"] > 80: return 'You can charge penalty points up to the point where the remaining earnings of citizen 1 become zero.' elif value["punishment4j"] > 70: return 'You can charge penalty points up to the point where the remaining earnings of citizen 1 become zero.' elif value["punishment5j"] > 60: return 'You can charge penalty points up to the point where the remaining earnings of citizen 1 become zero.' elif value["punishment6j"] > 50: return 'You can charge penalty points up to the point where the remaining earnings of citizen 1 become zero.' elif value["punishment7j"] > 40: return 'You can charge penalty points up to the point where the remaining earnings of citizen 1 become zero.' elif value["punishment8j"] > 30: return 'You can charge penalty points up to the point where the remaining earnings of citizen 1 become zero.' elif value["punishment9j"] > 20: return 'You can charge penalty points up to the point where the remaining earnings of citizen 1 become zero.' elif value["punishment10j"] > 10: return 'You can charge penalty points up to the point where the remaining earnings of citizen 1 become zero.' # @staticmethod # def app_after_this_page(player, upcoming_apps): # print('upcoming_apps is', upcoming_apps) # return "part1task3" page_sequence = [Start, Instructions, StartTask, Round1, Round1Amount, Round2, Round3]