from otree.api import * c = cu doc = '\nThis bargaining game involves 2 players. Each demands for a portion of some\navailable amount. If the sum of demands is no larger than the available\namount, both players get demanded portions. Otherwise, both get nothing.\n' class Constants(BaseConstants): name_in_url = 'bargaining' players_per_group = 2 num_rounds = 1 amount_shared = cu(100) instructions_template = 'bargaining/instructions.html' class Subsession(BaseSubsession): pass def set_payoffs(group): players = group.get_players() group.total_requests = sum([p.request for p in players]) if group.total_requests <= Constants.amount_shared: for p in players: p.payoff = p.request else: for p in players: p.payoff = c(0) class Group(BaseGroup): total_requests = models.CurrencyField() def other_player(player): group = player.group return player.get_others_in_group()[0] class Player(BasePlayer): request = models.CurrencyField(doc='Amount requested by this player', label='Please enter an amount from 0 to 100', max=Constants.amount_shared, min=0) class Introduction(Page): form_model = 'player' class Request(Page): form_model = 'player' form_fields = ['request'] class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player): return dict(other_player_request=other_player(player).request) page_sequence = [Introduction, Request, ResultsWaitPage, Results]