from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'Spiel' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 COMPLETION_CODE = "C1JPLZ94" class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # Main Variables Choice = models.IntegerField(blank=True, initial=0, choices=[[1, "1"], [2, "2"]]) reveal = models.IntegerField(blank=True, initial=0, choices=[[1, "1"], [0, "0"]]) reveal_urn = models.IntegerField(blank=True, initial=0, choices=[[1, "1"]]) bet_color = models.IntegerField(blank=True, initial=0) # Control Variables Control01 = models.IntegerField(initial=0, choices=[[1, "1"], [2, "2"], [3, "3"]]) Control02 = models.IntegerField(initial=0, choices=[[1, "1"], [2, "2"], [3, "3"]]) Control11 = models.IntegerField(initial=0) Control12 = models.IntegerField(initial=0) Control21 = models.IntegerField(initial=0) Control22 = models.IntegerField(initial=0) incorrect_attempts_welcome = models.IntegerField(initial=0) incorrect_attempts_instruction1 = models.IntegerField(initial=0) incorrect_attempts_instruction2 = models.IntegerField(initial=0) save_incorrect_attempts_welcome = models.IntegerField(initial=0) save_incorrect_attempts_instruction1 = models.IntegerField(initial=0) save_incorrect_attempts_instruction2 = models.IntegerField(initial=0) #Control questions understanding_question_start = models.IntegerField(blank=True, initial=0, label="Understanding question: Which of the following statements is true?", choices=[[1, "My decision will influence the additional payments from this study."], [2, "My decision will NOT influence the additional payments from this study."], [3, "My decision will influence the additional payments from this study if " "I am randomly selected to be the active player in my group"]]) understanding_question1 = models.IntegerField(blank=True, initial=0, label="Understanding question: As an active player, you will receive more money if…", choices=[[1, "…you choose High irrespective of the situation."], [2, "…you choose Low irrespective of the situation."], [3, "…you choose High in Situation 1 and B in Situation 2"], [4, "…you choose Low in Situation 1 and A in Situation 2. "]]) understanding_question2 = models.IntegerField(blank=True, initial=0, label="Understanding question: The passive player will receive more money if...", choices=[[1, "…you choose High irrespective of the situation."], [2, "…you choose Low irrespective of the situation."], [3, "…you choose High in Situation 1 and Low in Situation 2"], [4, "…you choose Low in Situation 1 and High in Situation 2. "]]) #Questionnaire age = models.FloatField(label="How old are you?", min=16, max=99) gender = models.IntegerField(label="What is your gender?", widget=widgets.RadioSelect, initial=-1, choices=[[0, "Male"], [1, "Female"], [2, "Other"], [3, "Prefer not to answer"]] ) education = models.IntegerField(label="What is the highest level of education you have completed?", widget=widgets.RadioSelect, initial=-1, choices=[[0, "Master’s degree or above"], [1, "Bachelor’s degree"], [2, "High school diploma"], [3, "Other"], [4, "Prefer not to answer"]]) country = models.StringField(label="In which country do you live in the moment?") Prolific_ID = models.StringField(label="What is your Prolific ID?") # Treatment and Display Variables treatment = models.IntegerField(initial=0) # 1=Full 2=Base treatment_string = models.StringField() # additional save treatment names here # Ai_or_ci is_Ai = models.BooleanField() is_mobile = models.BooleanField() # make our own dictator is_dictator = models.BooleanField() # Check if player is on last page is_ready = models.BooleanField(initial=False) # random number is_green_color = models.IntegerField() # Payment Variables dictator_pay_self = models.IntegerField(initial=60) participiation_fee = models.IntegerField(initial=100) # Choice==1 =60 ==2 =50 dictator_pay_other = models.IntegerField(initial=60) # if game_played==1: if Choice==1:Dictator_pay_other=50 elseif Choice==2:Dictator_pay_other=10 else # if game_played==2: if Choice==1:Dictator_pay_other=10 elseif Choice==2:Dictator_pay_other=50 else receive_pay = models.IntegerField(initial=50) # find player with same group and is_dictator :Dictator_pay_other bonus1 = models.IntegerField(initial=0) # if role=1 (dictator) bonus1=dictator_pay_self # if role=2 (recipient) bonus1=recieve_pay totalbonus = models.IntegerField(initial=0) def set_bonus1(self,value): self.bonus1 = value def set_receive_pay(self, value): self.receive_pay = value def set_totalbonus(self, value): self.totalbonus = value def get_bonus1(self): return self.bonus1 def get_is_ready(self): return self.is_ready def set_payoff(self, value): self.payoff = value def get_save_incorrect_attempts_welcome(self): return self.save_incorrect_attempts_welcome def get_save_incorrect_attempts_instruction1(self): return self.save_incorrect_attempts_instruction1 def get_save_incorrect_attempts_instruction2(self): return self.save_incorrect_attempts_instruction2 # Create an evenly distributed amount of players per treatment def creating_session(subsession): import itertools import math treatment_number = itertools.cycle([1,1,1,1,0,0,0,0]) ai_or_ci = itertools.cycle([False, False, True,True]) dictator_or_receiver = itertools.cycle([True, False]) for player in subsession.get_players(): # Assign treatment and ai or ci player.treatment = next(treatment_number) player.is_Ai = next(ai_or_ci) player.is_dictator = next(dictator_or_receiver) # Random number for each player if random.randint(1, 100) < 61: player.is_green_color = 1 else: player.is_green_color = 0 if player.treatment == 0: player.treatment_string = "fullinfo" if player.treatment == 1: player.treatment_string = "baseline" # PAGES class WelcomePage(Page): form_model = "player" form_fields = ["Control01", "incorrect_attempts_welcome",'is_mobile', 'Prolific_ID'] @staticmethod def is_displayed(player: Player): return player.treatment < 2 @staticmethod def error_message(player, values): print('values is', values) if values['Control01'] != 3: player.incorrect_attempts_welcome += 1 return 'Your answer was wrong. Please carefully read the description on this page again!' @staticmethod def vars_for_template(player: Player): player.save_incorrect_attempts_welcome = player.incorrect_attempts_welcome class InstructionsControl(Page): form_model = "player" form_fields = ["Control11", "Control12", "incorrect_attempts_instruction1"] @staticmethod def is_displayed(player: Player): return player.treatment == 1 @staticmethod def error_message(player, values): print('values is', values) if (values['Control11'] != 1) or (values['Control12'] != 4): player.incorrect_attempts_instruction1 += 1 return "Your answer was wrong. Please carefully read the description on this page again!" @staticmethod def vars_for_template(player: Player): player.save_incorrect_attempts_instruction1 = player.incorrect_attempts_instruction1 class InstructionsTreatment(Page): form_model = "player" form_fields = ["Control11", "Control12", "incorrect_attempts_instruction1"] @staticmethod def is_displayed(player: Player): return player.treatment == 0 @staticmethod def error_message(player, values): print('values is', values) if (values['Control11'] != 1) or (values['Control12'] != 4): player.incorrect_attempts_instruction1 += 1 return "Your answer was wrong. Please carefully read the description on this page again!" @staticmethod def vars_for_template(player: Player): player.save_incorrect_attempts_instruction1 = player.incorrect_attempts_instruction1 class DecisionControl(Page): form_model = "player" form_fields = ["Choice", "reveal"] @staticmethod def is_displayed(player: Player): return player.treatment == 1 class DecisionTreatment(Page): form_model = "player" form_fields = ["Choice", "reveal"] @staticmethod def is_displayed(player: Player): return player.treatment == 0 class DecisionRevealSituation1(Page): form_model = "player" form_fields = ["Choice"] @staticmethod def is_displayed(player: Player): return player.is_Ai == True and player.reveal == 1 class DecisionRevealSituation2(Page): form_model = "player" form_fields = ["Choice"] @staticmethod def is_displayed(player: Player): return player.is_Ai == False and player.reveal == 1 class Questionnaire(Page): form_model = "player" form_fields = ['age', 'gender', 'education', 'country'] class ResultPage(Page): form_model = "player" @staticmethod def vars_for_template(player): player.is_ready = True if player.Choice == 1: player.dictator_pay_self = 60 elif player.Choice == 2: player.dictator_pay_self = 50 else: player.dictator_pay_self = 60 if player.Choice == 1: if player.is_Ai == True: player.dictator_pay_other = 50 else: player.dictator_pay_other = 10 if player.Choice == 2: if player.is_Ai == True: player.dictator_pay_other = 10 else: player.dictator_pay_other = 50 ### calculation of bonus payment if player.is_dictator == 1: # suche partner und setze partner.recieve_pay auf meine self.dictator_pay_other # setze bonus der anderen person auf selbe variable my_partner = player.get_others_in_group() is_partner_ready = my_partner[0].get_is_ready() if is_partner_ready == False: my_partner[0].set_receive_pay(player.dictator_pay_other) my_partner[0].set_bonus1(player.dictator_pay_other) if player.treatment < 3: final_payoff = my_partner[0].get_bonus1() if my_partner[0].get_save_incorrect_attempts_welcome() > 2 \ or my_partner[0].get_save_incorrect_attempts_instruction1() > 2 \ or my_partner[0].get_save_incorrect_attempts_instruction2() > 2: final_payoff = 0 my_partner[0].set_totalbonus(final_payoff) my_partner[0].set_payoff(final_payoff) my_partner[0].set_receive_pay(player.dictator_pay_other) my_partner[0].set_bonus1(player.dictator_pay_other) player.bonus1 = player.dictator_pay_self if player.is_dictator == 0: my_partner = player.get_others_in_group() is_partner_ready = my_partner[0].get_is_ready() if is_partner_ready == False: player.bonus1 = 50 player.totalbonus = player.bonus1 if player.save_incorrect_attempts_welcome > 2 or player.save_incorrect_attempts_instruction1 > 2 or player.save_incorrect_attempts_instruction2 > 2: player.totalbonus = 0 player.payoff = player.totalbonus + player.participiation_fee return dict( ) page_sequence = [WelcomePage, InstructionsControl, InstructionsTreatment, DecisionControl, DecisionTreatment, DecisionRevealSituation1, DecisionRevealSituation2, Questionnaire, ResultPage]