from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = """ This bargaining game involves 2 players. Each demands for a portion of some available amount. If the sum of demands is no larger than the available amount, both players get demanded portions. Otherwise, both get nothing. """ class Constants(BaseConstants): name_in_url = 'bargaining' players_per_group = 2 num_rounds = 4 instructions_template = 'bargaining/instructions.html' amount_shared = c(100) class Subsession(BaseSubsession): def creating_session(self): import itertools chat = itertools.cycle([True, False]) for g in self.get_groups(): g.treatment = next(chat) class Group(BaseGroup): total_requests = models.CurrencyField() treatment = models.BooleanField() def set_payoffs(self): players = self.get_players() self.total_requests = sum([p.final_request for p in players]) if self.total_requests <= Constants.amount_shared: for p in players: p.payoff = p.final_request else: for p in players: p.payoff = c(0) class Player(BasePlayer): request = models.CurrencyField( doc=""" Amount requested by this player. """, min=0, max=Constants.amount_shared ) final_request = models.CurrencyField( doc=""" Final amount requested by this player. """, min=0, max=Constants.amount_shared ) def other_player(self): return self.get_others_in_group()[0]