from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ This is a one-period public goods game with 3 players. """ class Constants(BaseConstants): name_in_url = 'my.public_goods' players_per_group = 3 num_rounds = 2 instructions_template = 'public_goods/instructions.html' # """Amount allocated to each player""" endowment = c(100) multiplier = 2 class Subsession(BaseSubsession): def creating_session(self): print('in creating_session',self.round_number) #if self.round_number == 1: # paying_round = random.randint(1,Constants.num_rounds) # self.session.vars['paying_round'] = paying_round # print('set the paying round to', paying_round) class Group(BaseGroup): total_contribution = models.CurrencyField() cumulative_payoff = models.CurrencyField() #individual_share = models.CurrencyField() def set_payoffs(self): self.cumulative_payoff = sum([p.contribution for p in self.player.in_previous_rounds()]) self.total_contribution = sum([p.contribution for p in self.get_players()]) #self.individual_share = self.total_contribution * Constants.multiplier / Constants.players_per_group for p in self.get_players(): p.payoff = self.cumulative_payoff # + self.individual_share class Player(BasePlayer): contribution = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", )