from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '\nThis is a one-period public goods game with 3 players.\n' class Constants(BaseConstants): name_in_url = 'my_public_goods' players_per_group = 3 num_rounds = 1 endowment = c(100) multiplier = 2 admin_report_template = 'my_public_goods/admin_report.html' instructions_template = 'my_public_goods/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() def set_payoffs(self): players = self.get_players() print('in payoff function') contributions = [p.Contribution for p in players] print('contributions:', contributions) self.total_contribution = sum(contributions) self.individual_share = self.total_contribution * Constants.endowment / Constants.players_per_group print('individual share', self.individual_share) for p in players: p.payoff = Constants.endowment - p.Contribution + self.individual_share print('payoff after', p.payoff) class Player(BasePlayer): Contribution = models.CurrencyField(doc='The amount contributed by the player', label='How much will you contribute?', max=Constants.endowment, min=0)