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 = 'htlj1' players_per_group = None num_rounds = 1 instructions_template = 'htlj1/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) check1 = ['10', '90', '100', '110'] 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() removed=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 self.removed = 55 - sum([p.contribution for p in self.get_players()]) for p in self.get_players(): p.payoff2 = Constants.endowment - p.contribution + self.individual_share if p.contribution >= 55: 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.removed = 0 elif p.contribution < 55: 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 - self.removed p.removed = self.removed class Player(BasePlayer): check1 = models.CharField(choices=Constants.check1) check2 = models.CharField(choices=['Group Member', 'Group Enforcer', 'Group Observer', 'Group Coordinator' ], widget=widgets.RadioSelect) check3 = models.CharField(choices=['Removes points from the Group Members using Enforcement Tax Points', 'Do nothing', 'Contribute to the group project' ], widget=widgets.RadioSelect) s2q1attempt = models.IntegerField(initial=0) s2q2attempt = models.IntegerField(initial=0) s2q3attempt = models.IntegerField(initial=0) pointremoved = models.CurrencyField() removed=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)