from otree.api import * c = cu doc = '\nThis is a standard 2-player trust game where the amount sent by player 1 gets\ntripled. The trust game was first proposed by\n\n Berg, Dickhaut, and McCabe (1995)\n.\n' class Constants(BaseConstants): name_in_url = 'trust' players_per_group = 2 num_rounds = 1 endowment = cu(100) multiplier = 3 instructions_template = 'trust/instructions.html' class Subsession(BaseSubsession): pass def sent_back_amount_max(group): return group.sent_amount * Constants.multiplier def set_payoffs(group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p1.payoff = Constants.endowment - group.sent_amount + group.sent_back_amount p2.payoff = group.sent_amount * Constants.multiplier - group.sent_back_amount class Group(BaseGroup): sent_amount = models.CurrencyField(doc='Amount sent by P1', label='Please enter an amount from 0 to 100', max=Constants.endowment, min=0) sent_back_amount = models.CurrencyField(doc='Amount sent back by P2', min=0) class Player(BasePlayer): pass class Introduction(Page): form_model = 'player' class Send(Page): form_model = 'group' form_fields = ['sent_amount'] @staticmethod def is_displayed(player): group = player.group return player.id_in_group == 1 class SendBackWaitPage(WaitPage): pass class SendBack(Page): form_model = 'group' form_fields = ['sent_back_amount'] @staticmethod def is_displayed(player): group = player.group return player.id_in_group == 2 @staticmethod def vars_for_template(player): group = player.group tripled_amount = group.sent_amount * Constants.multiplier return dict(tripled_amount=tripled_amount) class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player): group = player.group return dict(tripled_amount=group.sent_amount * Constants.multiplier) page_sequence = [Introduction, Send, SendBackWaitPage, SendBack, ResultsWaitPage, Results]