from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'trust' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 10 INSTRUCTIONS_TEMPLATE = 'instructions.html' # Initial amount allocated to each player ENDOWMENT = 100 MULTIPLIER = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): sent_amount = models.CurrencyField( min=0, max=C.ENDOWMENT, doc="""信頼者から送られたポイント""" ) sent_back_amount = models.CurrencyField(doc="""被信頼者から送られたポイント""", min=0) def sent_back_amount_max(self): return self.sent_amount * C.MULTIPLIER def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.payoff = C.ENDOWMENT - self.sent_amount + self.sent_back_amount p2.payoff = self.sent_amount * C.MULTIPLIER - self.sent_back_amount class Player(BasePlayer): pass def creating_session(subsession): subsession.group_randomly() class Introduction(Page): def is_displayed(self): return self.round_number == 1 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'] def is_displayed(self): return self.id_in_group == 1 class SendBackWaitPage(WaitPage): pass 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'] def is_displayed(self): return self.id_in_group == 2 def vars_for_template(self): tripled_amount = self.group.sent_amount * C.MULTIPLIER return dict( tripled_amount=tripled_amount, prompt='Please an amount from 0 to {}'.format(tripled_amount), ) class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' class Results(Page): """This page displays the earnings of each player""" def vars_for_template(self): return dict(tripled_amount=self.group.sent_amount * C.MULTIPLIER) page_sequence = [ Introduction, Send, SendBackWaitPage, SendBack, ResultsWaitPage, Results, ]