from otree.api import * doc = """ This is a standard 2-player trust where the amount sent by player 1 gets tripled. The trust was first proposed by Berg, Dickhaut, and McCabe (1995) . """ class C(BaseConstants): NAME_IN_URL = 'trust2' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 INSTRUCTIONS_TEMPLATE = 'trust2/Instructions.html' # Initial amount allocated to each player ENDOWMENT = cu(100) MULTIPLIER = 3 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)) class Player(BasePlayer): pass # FUNCTIONS 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 # PAGES class Introduction(Page): @staticmethod def is_displayed(player: Player): return player.participant.vars['consent'].lower() == 'consent' class Send(Page): """This page is only for P1 P1 sends amount (all, some, or none) to P2 This amount is tripled by experimenter, i.e if sent amount by P1 is 5, amount received by P2 is 15""" form_model = 'group' form_fields = ['sent_amount'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 1 and player.participant.vars['consent'].lower() == 'consent' class SendBackWaitPage(WaitPage): @staticmethod def is_displayed(player: Player): return player.participant.vars['consent'].lower() == 'consent' class SendBack(Page): """This page is only for P2 P2 sends back some amount (of the tripled amount received) to P1""" form_model = 'group' form_fields = ['sent_back_amount'] @staticmethod def is_displayed(player: Player): return player.id_in_group == 2 and player.participant.vars['consent'].lower() == 'consent' @staticmethod def vars_for_template(player: Player): group = player.group tripled_amount = group.sent_amount * C.MULTIPLIER return dict(tripled_amount=tripled_amount) class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs @staticmethod def is_displayed(player: Player): return player.participant.vars['consent'].lower() == 'consent' class Results(Page): """This page displays the earnings of each player""" @staticmethod def vars_for_template(player: Player): group = player.group return dict(tripled_amount=group.sent_amount * C.MULTIPLIER) @staticmethod def is_displayed(player: Player): player.participant.vars['payoff_trust'] = player.payoff return player.participant.vars['consent'].lower() == 'consent' page_sequence = [ Introduction, Send, SendBackWaitPage, SendBack, ResultsWaitPage, Results, ]