from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ One player decides how to divide a certain amount between himself and the other player. See: Kahneman, Daniel, Jack L. Knetsch, and Richard H. Thaler. "Fairness and the assumptions of economics." Journal of business (1986): S285-S300. """ class Constants(BaseConstants): name_in_url = 'dictator' players_per_group = None num_rounds = 1 instructions_template = 'real_effort/instructions.html' # Initial amount allocated to the dictator endowment = c(100) # Randomize initial endowment income_list = [c(10), c(100), c(500)] initial_income = random.choice(income_list) # Randomize partner's endowment partner_income = random.choice(income_list) class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): p.initial = random.choice(Constants.income_list) p.partner = random.choice(Constants.income_list) class Group(BaseGroup): kept = models.CurrencyField( doc="""Amount dictator decided to keep for himself""", min=0, max=Constants.endowment, ) def set_payoffs(self): p1 = self.get_player_by_id(1) p1.payoff = self.kept + Constants.initial_income p1.kept = self.kept class Player(BasePlayer): initial = models.CurrencyField( label='What is the initial endowment?' ) partner = models.CurrencyField( label='What is my partners endowment' ) kept = models.CurrencyField( label='Income split choice' )