from otree.api import * c = cu doc = '\nOne player decides how to divide a certain amount between himself and the other\nplayer.\nSee: Kahneman, Daniel, Jack L. Knetsch, and Richard H. Thaler. "Fairness\nand the assumptions of economics." Journal of business (1986):\nS285-S300.\n' class C(BaseConstants): NAME_IN_URL = 'dictator' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 4 ENDOWMENT = cu(15) INSTRUCTIONS_TEMPLATE = 'dictator/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): kept = models.CurrencyField(doc='Amount dictator decided to keep for himself', label='If you will take 15 another player will get 150 or if you will take 5 another player will get 50', max=C.ENDOWMENT, min=5) def set_payoffs(group: Group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p1.payoff = group.kept p2.payoff =(group.kept*10) class Player(BasePlayer): pass class Introduction(Page): form_model = 'player' class Offer(Page): form_model = 'group' form_fields = ['kept'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player: Player): group = player.group return dict(offer=group.kept*10) page_sequence = [Introduction, Offer, ResultsWaitPage, Results]