from otree.api import * c = cu doc = '\nSimple trust game\n' class Constants(BaseConstants): name_in_url = 'TrustGame' players_per_group = 2 num_rounds = 1 endowment = cu(1) multiplier = 3 instructions_template = 'TrustGame/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 def set_norm_value(group): for p in group.get_players(): p.norm = p.participant.vars['norm'] class Group(BaseGroup): sent_amount = models.CurrencyField(doc='Amount sent by P1', label='How much do you want to send to Participant B', max=Constants.endowment, min=0) sent_back_amount = models.CurrencyField(doc='Amount sent back by P2', label='How much do you want to send back', min=0) sent_back_amount_max = sent_back_amount_max set_payoffs = set_payoffs set_norm_value = set_norm_value class Player(BasePlayer): norm = models.StringField(choices=[['Hospitality', 'Hospitality'], ['Self-Reliance', 'Self-Reliance']], label='Under normal times (before or after Covid) if a friend of yours were coming to town would you more likely support the norm of hospitality or the norm of self-reliance?', widget=widgets.RadioSelectHorizontal) normCheck = models.StringField(label='Enter the norm YOU selected:') normCheckOther = models.StringField(label='Enter the norm the OTHER player selected:') PlatformID = models.StringField(label='Please enter your MTurk ID') class Grouping(WaitPage): group_by_arrival_time = True after_all_players_arrive = 'set_norm_value' class NormAwareness(Page): form_model = 'player' form_fields = ['normCheck', 'normCheckOther'] timeout_seconds = 120 class Send(Page): form_model = 'group' form_fields = ['sent_amount'] @staticmethod def is_displayed(player): group = player.group return player.id_in_group == 1 @staticmethod def vars_for_template(player): group = player.group return dict(otherp = player.get_others_in_group()[0]) class WaitForP1(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 return dict(tripled_amount=group.sent_amount * Constants.multiplier, otherp = player.get_others_in_group()[0]) 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(otherp = player.get_others_in_group()[0]) class PlatformID(Page): form_model = 'player' form_fields = ['PlatformID'] class Survey(Page): form_model = 'player' page_sequence = [Grouping, NormAwareness, Send, WaitForP1, SendBack, ResultsWaitPage, Results, PlatformID, Survey]