from otree.api import * doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'trustgame_learning' players_per_group = 2 num_rounds = 1 completion_code='12345' endowment = cu(10) multiplication_factor = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): #useful to save group level variables, also if info is shared, also if only one player needs to do smth sent_amount = models.CurrencyField( label="How much do you want to send to participant B?", min=cu(0), max=Constants.endowment ) sent_back_amount = models.CurrencyField( label="How much would you like to send back?" ) class Player(BasePlayer): #write functions pass #### Specify functions #### def sent_back_amount_choices(group): #this fctn automatically runs since it is connected by name to sent_back_amount return currency_range( cu(0), #min group.sent_amount * Constants.multiplication_factor, #max cu(1) #increments ) 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.multiplication_factor - group.sent_back_amount ############################ # PAGES class Send(Page): form_model = 'group' form_fields = ['sent_amount'] @staticmethod def is_displayed(player): return player.id_in_group == 1 class WaitforP1(WaitPage): pass class SendBack(Page): form_model = 'group' form_fields = ['sent_back_amount'] @staticmethod def is_displayed(player): return player.id_in_group == 2 @staticmethod def vars_for_template(player): group=player.group return dict( tripled_amount=group.sent_amount * Constants.multiplication_factor ) class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): pass page_sequence = [Send, WaitforP1, SendBack, ResultsWaitPage, Results]