from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Priyama Majumdar' doc = """ Modified Public Goods Game """ class Constants(BaseConstants): name_in_url = 'exp1' players_per_group = 2 num_rounds = 2 initial_endowment = 200 alpha = 0.25 class Subsession(BaseSubsession): def creating_session(self): num_players = len(self.get_players()) num_groups = int(num_players/2) self.group_randomly() #Grouping changes every round class Group(BaseGroup): def set_payoffs(self): total_public_pot = sum([p.group_contribution for p in self.get_players()]) for p in self.get_players(): guess = (total_public_pot - p.group_contribution) / 1 p.private_contri = Constants.initial_endowment - p.group_contribution if p.card_number >= guess-5 and p.card_number <= guess+5: p.round_payoff = p.private_contri + int(Constants.alpha*total_public_pot)+10 else: p.round_payoff = p.private_contri + int(Constants.alpha*total_public_pot) class Player(BasePlayer): def set_final_payoff(self): all_rounds_payoffs = [p.round_payoff for p in self.in_all_rounds()] self.participant.vars['blah']=list(all_rounds_payoffs) card_number = models.IntegerField(min=0,max=200, label="How much do you think others will contribute on an average? You will receieve a bonus of Rs.10 if your guess is correct or within five rupees of the average contribution made by the other players.") paying_round = models.IntegerField() group_contribution = models.IntegerField(min=0, max=200, label="Amount you want to put in Group Account") private_contri = models.IntegerField() round_payoff = models.IntegerField()