from otree.api import * c = cu doc = '\nOne player decides how to divide a certain amount between himself and the other\nplayer.\nSee: Kahneman, Daniel, Jack L. Knetsch, and Richard H. Thaler. "Fairness\nand the assumptions of economics." Journal of business (1986):\nS285-S300.\n' class C(BaseConstants): NAME_IN_URL = 'dictator_diverse' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 ENDOWMENT = cu(12) INSTRUCTIONS_TEMPLATE = 'dictator_diverse/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): kept = models.CurrencyField(doc='Amount dictator decided to keep for himself', label='I will keep', max=C.ENDOWMENT, min=0) sent = models.CurrencyField(max=C.ENDOWMENT, min=0) def set_payoffs(group: Group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) if (p1.decision_pay == "choice_first"): if (p2.choice_invest == "A"): group.sent = p1.info_firstA_send if (p2.choice_invest == "B"): group.sent = p1.info_firstB_send if (p1.decision_pay == "info_first"): if (p2.initial_endowment == 4): group.sent = p1.info_first4_send if (p2.initial_endowment == 8): group.sent = p1.info_first8_send if (p1.decision_pay == "all_first"): if (p2.initial_endowment == 4 and p2.choice_invest == "A"): group.sent = p1.info_first4A_send if (p2.initial_endowment == 4 and p2.choice_invest == "B"): group.sent = p1.info_first4B_send if (p2.initial_endowment == 8 and p2.choice_invest == "A"): group.sent = p1.info_first8A_send if (p2.initial_endowment == 8 and p2.choice_invest == "B"): group.sent = p1.info_first8B_send p1.earn_from_dict = C.ENDOWMENT -group.sent p2.earn_from_dict = group.sent p1.payoff = C.ENDOWMENT -group.sent + p1.earn_from_invest p2.payoff = group.sent + p2.earn_from_invest p1.color = 'blue' p2.color = 'green' p1.pay_plus_fee = p1.payoff + 5 p2.pay_plus_fee = p2.payoff + 5 Group.set_payoffs = set_payoffs class Player(BasePlayer): initial_endowment = models.IntegerField(initial=4) is_question1_correct = models.BooleanField(initial=False) is_question2_correct = models.BooleanField() decision_pay = models.StringField() coin_flip = models.StringField() choice_invest = models.StringField(choices=[['A', 'A'], ['B', 'B']]) info_firstA_send = models.CurrencyField(label='Send the following amount if the green player chose Option A (Keep)', max=C.ENDOWMENT, min=0) info_firstB_send = models.CurrencyField(label='Send the following amount if the green player chose Option B', max=C.ENDOWMENT, min=0) earn_from_dict = models.CurrencyField(max=C.ENDOWMENT, min=0) info_first4_send = models.CurrencyField(label='Send the following amount if the green player had an initial payout of $4', max=C.ENDOWMENT, min=0) info_first8_send = models.CurrencyField(label='Send the following amount if the green player had an initial payout of $8', max=C.ENDOWMENT, min=0) info_first4A_send = models.CurrencyField(label='Send the following amount if the green player had an initial payout of $4 and chose A (Keep)', max=C.ENDOWMENT, min=0) info_first4B_send = models.CurrencyField(label='Send the following amount if the green player had an initial payout of $4 and chose B', max=C.ENDOWMENT, min=0) info_first8A_send = models.CurrencyField(label='Send the following amount if the green player had an initial payout of $8 and chose A (Keep)', max=C.ENDOWMENT, min=0) info_first8B_send = models.CurrencyField(label='Send the following amount if the green player had an initial payout of $8 and chose B', max=C.ENDOWMENT, min=0) earn_from_invest = models.CurrencyField(min=0) question1 = models.CurrencyField(label='Quiz: Knowing your initial payoff from the first coin flip, how much would you earn if you doubled your payoff? (Hint: Multiply your payoff in the first stage by 2.)', max=20, min=0) question2 = models.CurrencyField(label='Quiz: What will you earn for stage 1 if you select Option B and then the computer flips Tails?', min=0) q3_sending = models.IntegerField(label='Type "1", "2", or "3" from the choices above', max=3, min=1) pay_plus_fee = models.CurrencyField(min=0) color = models.StringField() sex = models.StringField(choices=[['Male', 'Male'], ['Female', 'Female']], label='What is your sex at birth?') age = models.IntegerField(label='Please enter your age', max=90, min=18) major = models.StringField(choices=[['Business or Economics', 'Business or Economics'], ['Science or Engineering', 'Science or Engineering'], ['Liberal Arts (English, Communication, etc.)', 'Liberal Arts (English, Communication, etc.)'], ['Nursing', 'Nursing'], ['Education', 'Education'], ['Other', 'Other']], label='Your college major (select one)') risk = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5']], label='Select One Choice Below') coin_flip_risk = models.StringField() risk_payout = models.CurrencyField(min=0) def invest_earn(player: Player): if (player.choice_invest=="A"): player.earn_from_invest = player.initial_endowment if (player.choice_invest=="B"): if (player.coin_flip == "heads"): player.earn_from_invest = player.initial_endowment * 2 if (player.coin_flip == "tails"): player.earn_from_invest = 4 Player.invest_earn = invest_earn class Welcome(Page): form_model = 'player' @staticmethod def before_next_page(player: Player, timeout_happened): import random player.initial_endowment = random.choice([4, 8]) player.coin_flip = random.choice(['heads', 'tails']) player.coin_flip_risk = random.choice(['heads', 'tails']) player.decision_pay = random.choice(['info_first', 'choice_first', 'all_first']) class Welcome2(Page): form_model = 'player' class Instruct1(Page): form_model = 'player' class Assign_Init_Endowment(Page): form_model = 'player' class Timeline(Page): form_model = 'player' class Endow_Quiz(Page): form_model = 'player' form_fields = ['question1'] @staticmethod def before_next_page(player: Player, timeout_happened): player.is_question1_correct = ( player.question1 == 2 * player.initial_endowment ) @staticmethod def error_message(player: Player, values): if values["question1"] != 2 * player.initial_endowment: return 'Answer is incorrect' class Endow_Quiz_Feedback(Page): form_model = 'player' class Tails_Quiz(Page): form_model = 'player' form_fields = ['question2'] @staticmethod def before_next_page(player: Player, timeout_happened): player.is_question2_correct = ( player.question2 == 4 ) @staticmethod def error_message(player: Player, values): if values["question2"] != 4: return 'Answer is incorrect' class Invest_Choice(Page): form_model = 'player' form_fields = ['choice_invest'] class SecondCoinFlip(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.choice_invest == "B" class Coin_Result(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.choice_invest == "B" class Instruct_Dictate(Page): form_model = 'player' class InstructDictate2(Page): form_model = 'player' class Timeline2(Page): form_model = 'player' class Dictate_Quiz(Page): form_model = 'player' form_fields = ['q3_sending'] @staticmethod def error_message(player: Player, values): if values["q3_sending"] != 2: return 'Answer is incorrect' class InfoChoice(Page): form_model = 'player' form_fields = ['info_firstA_send', 'info_firstB_send'] @staticmethod def before_next_page(player: Player, timeout_happened): if (player.choice_invest=="A"): player.earn_from_invest = player.initial_endowment if (player.choice_invest=="B"): if (player.coin_flip == "heads"): player.earn_from_invest = player.initial_endowment * 2 if (player.coin_flip == "tails"): player.earn_from_invest = 4 class InfoInitEndow(Page): form_model = 'player' form_fields = ['info_first4_send', 'info_first8_send'] class InfoAll(Page): form_model = 'player' form_fields = ['info_first8B_send', 'info_first4B_send', 'info_first4A_send', 'info_first8A_send'] class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player: Player): group = player.group return dict(offer=C.ENDOWMENT - group.sent) class Questions1(Page): form_model = 'player' form_fields = ['sex', 'age', 'major'] class Questions2(Page): form_model = 'player' form_fields = ['risk'] @staticmethod def before_next_page(player: Player, timeout_happened): if (player.risk == 1): player.risk_payout = 2 if (player.risk == 2): if (player.coin_flip_risk == "heads"): player.risk_payout = 3 if (player.coin_flip_risk == "tails"): player.risk_payout = 1.5 if (player.risk == 3): if (player.coin_flip_risk == "heads"): player.risk_payout = 4 if (player.coin_flip_risk == "tails"): player.risk_payout = 1 if (player.risk == 4): if (player.coin_flip_risk == "heads"): player.risk_payout = 5 if (player.coin_flip_risk == "tails"): player.risk_payout = .5 if (player.risk == 5): if (player.coin_flip_risk == "heads"): player.risk_payout = 6 if (player.coin_flip_risk == "tails"): player.risk_payout = 0 player.payoff = player.payoff + player.risk_payout player.pay_plus_fee = player.payoff + 5 class Final(Page): form_model = 'player' page_sequence = [Welcome, Welcome2, Instruct1, Assign_Init_Endowment, Timeline, Endow_Quiz, Endow_Quiz_Feedback, Tails_Quiz, Invest_Choice, SecondCoinFlip, Coin_Result, Instruct_Dictate, InstructDictate2, Timeline2, Dictate_Quiz, InfoChoice, InfoInitEndow, InfoAll, ResultsWaitPage, Results, Questions1, Questions2, Final]