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 = """ Stage 1 Round 1 """ class Constants(BaseConstants): name_in_url = 'stage1round2' players_per_group = None num_rounds = 1 instructions_template = 'karlstage1round2/aInstructions.html' endowment = c(100) initial_endowment = c(100) pool_multiplier = c(1.6) answer_increment = c(1) 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() 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()]) + 126 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([+58, +self.individual_share, ]) p.p2_payoff2 = sum([+55, +self.individual_share, ]) p.p3_payoff2 = sum([+61, +self.individual_share, ]) p.payoff = Constants.endowment - p.contribution + self.individual_share p.participant.vars['earning1'] = p.payoff2 class Player(BasePlayer): total_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)