from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '' class Constants(BaseConstants): name_in_url = 'PublicGoodGame3players' players_per_group = 3 num_rounds = 2 multiplier = 2 endowment = 14 instructions_template = 'PublicGoodGame3players/instructions.html' class Subsession(BaseSubsession): def creating_session(self): self.group_randomly(fixed_id_in_group = False) class Group(BaseGroup): individual_share = models.CurrencyField() total_contribution = models.CurrencyField() def set_payoff(self): contributions=0 partecipanti=0 for p in self.get_players(): if p.contribution == 99: pass else: partecipanti=partecipanti+1 contributions=contributions+p.contribution if partecipanti > 1: self.total_contribution = contributions * 2 self.individual_share= self.total_contribution/partecipanti if partecipanti == 1: self.total_contribution = 0 self.individual_share = 0 if partecipanti == 0: self.total_contribution = 0 self.individual_share = 0 for p in self.get_players(): if partecipanti > 1: if p.contribution == 99: p.payoff = Constants.endowment else: p.payoff = Constants.endowment - p.contribution + self.individual_share else: p.payoff = Constants.endowment p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) p1.partecipantipg = partecipanti p2.partecipantipg = partecipanti p3.partecipantipg = partecipanti def stringhe(self): for p in self.get_players(): p.progettocomunepl = None if p.contribution == 99: p.progettocomunepl = "Exit" if p.contribution == 0: p.progettocomunepl = "0 points" if p.contribution == 3: p.progettocomunepl = "3 points" if p.contribution == 6: p.progettocomunepl = "6 points" if p.contribution == 9: p.progettocomunepl = "9 points" class Player(BasePlayer): contribution = models.IntegerField(choices=[[0, '0'], [3, '3'], [6, '6'], [9, '9'], [99, 'Exit']], label='How much do you want to contribute to the common project?', widget=widgets.RadioSelect) pg = models.IntegerField(choices=[[18, '( 6 + 3 ) x 2 = 18'], [9, '( 6 + 3 ) = 9']], label='1) What is the value of the common project?', widget=widgets.RadioSelect) miopayoff = models.IntegerField(choices=[[20, '14(endowment)-3(contribution)+ 9(share of project) = 20'], [14, '14 (endowment) + 9 (share of project) = 23']], label='2) What is your payoff?', widget=widgets.RadioSelect) progettocomunepl = models.StringField() partecipantipg = models.IntegerField(max=Constants.players_per_group, min=0) def setglobals(self): self.participant.vars['OCIY_payoff'] = self.participant.payoff return(self.participant.vars)