from otree.api import * c = cu doc = '\nThis is a standard 2-player trust game where the amount sent by player 1 gets\nmultipled by 100. The trust game was first proposed by\n\n Berg, Dickhaut, and McCabe (1995)\n.\n' class C(BaseConstants): NAME_IN_URL = 'trust' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 5 ENDOWMENT = cu(10) MULTIPLIER = 100 INSTRUCTION = 'You have been randomly and anonymously paired with another participant. One of you will be selected at random to be participant A; the other will be participant B. You will learn whether you are participant A or B prior to making any decision. To start, participant A receives 10 points; participant B receives nothing. Participant A can send some or all of his 10 points to participant B. Before B receives this amount, it will be multiplied by 100. Once B receives the 100 times amount he can decide to send some or all of it to A.' INSTRUCTIONS_TEMPLATE = 'trust/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): sent_amount = models.CurrencyField(doc='Amount sent by P1', label='Please enter an amount from 0 to 10', max=C.ENDOWMENT, min=0) sent_back_amount = models.CurrencyField(doc='Amount sent back by P2', min=0) def sent_back_amount_max(group: Group): return group.sent_amount * C.MULTIPLIER def set_payoffs(group: Group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p1.payoff = C.ENDOWMENT - group.sent_amount + group.sent_back_amount p2.payoff = group.sent_amount * C.MULTIPLIER - group.sent_back_amount class Player(BasePlayer): Name = models.StringField(initial='Insert your name') net_id = models.StringField(initial='Insert your net ID') contributed = models.BooleanField() Gender = models.StringField(choices=[['Female', 'Female'], ['Male', 'Male'], ['Other recognitions', 'Other recognitions']]) Confidence = models.StringField(choices=[['Most easily', 'Most easily'], ['A little bit easily', 'A little bit easily'], ['Rationale', 'Rationale'], ['Not very easily', 'Not very easily'], ['Never trust others', 'Never trust others']], initial='Do you usually trust people easily?') class Introduction(Page): form_model = 'player' form_fields = ['Name', 'net_id', 'Gender', 'Confidence'] @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Send(Page): form_model = 'group' form_fields = ['sent_amount'] timeout_seconds = 180 @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 @staticmethod def vars_for_template(player: Player): ap = [] for i in range(1, len(player.in_all_rounds())): ap.append(player.in_all_rounds()[i].payoff) total_payoff = sum(ap) return dict(all_payoff = ap, total_payoff = total_payoff) class SendBackWaitPage(WaitPage): title_text = 'Please waiting for the others to complete the game!' class SendBack(Page): form_model = 'group' form_fields = ['sent_back_amount'] timeout_seconds = 180 @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 2 @staticmethod def vars_for_template(player: Player): group = player.group tripled_amount = group.sent_amount * C.MULTIPLIER ap = [] for i in range(1, len(player.in_all_rounds())): ap.append(player.in_all_rounds()[i].payoff) total_payoff = sum(ap) return dict(tripled_amount=tripled_amount, total_payoff = total_payoff, all_payoff = ap) class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs title_text = 'Please waiting for the others to complete the game!' class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player: Player): group = player.group ap = [] for i in range(len(player.in_all_rounds())): ap.append(player.in_all_rounds()[i].payoff) total_payoff = sum(ap) return dict(tripled_amount=group.sent_amount * C.MULTIPLIER, all_payoff = ap, total_payoff = total_payoff) page_sequence = [Introduction, Send, SendBackWaitPage, SendBack, ResultsWaitPage, Results]