from otree.api import * doc = """ This is a standard 2-player trust game where the amount sent by player 1 gets doubled. The trust game was first proposed by Berg, Dickhaut, and McCabe (1995) . """ class C(BaseConstants): NAME_IN_URL = 'trust' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 INSTRUCTIONS_TEMPLATE = 'trust/instructions.html' # Initial amount allocated to each player ENDOWMENT = cu(100) MULTIPLIER = 2 class Subsession(BaseSubsession): pass class Group(BaseGroup): sent_amount = models.CurrencyField( min=0, max=C.ENDOWMENT, doc="""Amount sent by P1""", label="Please enter an amount from 0 to 100:", ) sent_back_amount = models.CurrencyField( doc="""Amount sent back by P2""", min=cu(0), max=C.ENDOWMENT, label="Sent back amount:", ) class Player(BasePlayer): ID_quest = models.StringField( initial='', label=''' Write your identifier code (contains 7 digits).

Hint: First two digits of your grandmother's/mother's name, your date of birth, first two digits of your first school and the third letter of your last name.''', ) eval2 = models.IntegerField( label='Write the amount of test currency that equals 1 euro ', min=1, max=100 ) # FUNCTIONS def sent_back_amount_max(group: Group): return group.sent_amount * C.MULTIPLIER + C.ENDOWMENT 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 = C.ENDOWMENT + group.sent_amount * C.MULTIPLIER - group.sent_back_amount # PAGES class IDcode(Page): form_model = 'player' form_fields = ['ID_quest'] class Experiment_ID(Page): pass class Introtest(Page): """This page is for test amount sent for all participants """ form_model = 'player' form_fields = ['eval2'] class Introduction(Page): pass class Send(Page): """This page is only for P1 P1 sends amount (all, some, or none) to P2 This amount is doubled by experimenter, i.e if sent amount by P1 is 5, amount received by P2 is 10""" form_model = 'group' form_fields = ['sent_amount'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 #class SendBackWaitPage(WaitPage): #pass class SendBackWaitPage(WaitPage): template_name = 'trust/TrustWaitPage.html' class SendBack(Page): """This page is only for P2 P2 sends back some amount (of the doubled amount received) to P1""" form_model = 'group' form_fields = ['sent_back_amount'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 2 @staticmethod def vars_for_template(player: Player): group = player.group doubled_amount = group.sent_amount * C.MULTIPLIER return dict(doubled_amount=doubled_amount) class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): """This page displays the earnings of each player""" @staticmethod def vars_for_template(player: Player): group = player.group return dict(doubled_amount=group.sent_amount * C.MULTIPLIER) page_sequence = [ IDcode, Experiment_ID, Introtest, Introduction, Send, SendBackWaitPage, SendBack, ResultsWaitPage, Results, ]