from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) 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 = c(100) instructions_template = 'bargaining/instructions.html' class Subsession(BaseSubsession): success_pl1 = models.IntegerField() success_pl2 = models.IntegerField() class Group(BaseGroup): total_requests = models.CurrencyField() def set_payoffs(self): players = self.get_players() self.total_requests = sum([p.request for p in players]) if self.total_requests <= Constants.amount_shared: for p in players: p.payoff = p.request+(100-self.total_requests)/2 else: for p in players: p.payoff = c(0) class Player(BasePlayer): request = models.CurrencyField(doc='Amount requested by this player', max=Constants.amount_shared, min=0) success = models.IntegerField() def other_player(self): return self.get_others_in_group()[0]