from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) #from otree_tools.models.fields import OtherModelField import random import itertools author = 'FX CHEN' doc = """ This is a TPPG with leader not punishing. """ class Constants(BaseConstants): name_in_url = 'lthj1' players_per_group = None num_rounds = 1 instructions_template = 'lthj1/aInstructions.html' endowment = c(90) initial_endowment = c(90) take_away_endo = c(50) pool_multiplier = c(1.6) answer_increment = c(1) leader_decision = currency_range(0, take_away_endo, answer_increment) leader_decision_count = len(leader_decision) class Subsession(BaseSubsession): def creating_session(self): players = self.get_players() self.group_randomly() class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() current_payoff = models.CurrencyField() p1_payoff2 = models.CurrencyField() p2_payoff2 = models.CurrencyField() p3_payoff2 = models.CurrencyField() def set_payoffs(self): self.total_contribution = sum([p.contribution for p in self.get_players()]) + 174 self.individual_share = self.total_contribution * Constants.pool_multiplier / 4 for p in self.get_players(): p.payoff2 = Constants.endowment - p.contribution + self.individual_share if self.subsession.round_number == 1: p.p1_payoff2 = sum([+35, -0, +self.individual_share, ]) p.p2_payoff2 = sum([+30, -0, +self.individual_share, ]) p.p3_payoff2 = sum([+31, -0, +self.individual_share, ]) p.payoff = Constants.endowment - p.contribution + self.individual_share - 0 p.participant.vars['earning1'] = p.payoff2 class Player(BasePlayer): pointremoved = models.CurrencyField() payoff2 = models.CurrencyField() p1_payoff2 = models.CurrencyField() p2_payoff2 = models.CurrencyField() p3_payoff2 = models.CurrencyField() contribution = models.CurrencyField( min=0, max=Constants.endowment, doc="""The amount contributed by the player""", ) def member_id(self): # player 1 is the leader, so member 1 is actually player 2 return (self.id_in_group)