from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random class Constants(BaseConstants): name_in_url = 'dictatorEXP' players_per_group = None num_rounds = 1 instructions_template = 'EgalEXP/instructions.html' # Randomize initial endowment income_list = [c(10), c(100), c(300)] initial_income = random.choice(income_list) # Randomize partner's endowment partner_income = random.choice(income_list) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): choice = models.StringField( label='Income split choice', choices=['Choice 1 (50,50)', 'Choice 2 (75, 150)'], widget=widgets.RadioSelect ) initial = models.CurrencyField( label='What is the initial endowment?' ) partner = models.CurrencyField( label='What is my partners endowment' ) kept = models.CurrencyField( label='Amount earned from split' ) def set_payoffs(self): p1 = self.get_player_by_id(1) if self.choice == 'Choice 1 (50,50)': p1.kept = 50 p1.payoff = 50 + Constants.initial_income else: p1.kept = 75 p1.payoff = 75 + Constants.initial_income