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 = 'dictatorwnames' players_per_group = 2 num_rounds = 1 instructions_template = 'dictatorwnames/instructions.html' # Initial amount allocated to the dictatorwnames endowment = c(100) class Subsession(BaseSubsession): def creating_session(self): # randomize to treatments for player in self.get_players(): player.name = random.choice(['James','John','Robert','Michael','William', 'Mary','Patricia','Linda','Barbara','Lily']) print('set player.name to', player.name) class Group(BaseGroup): kept = models.CurrencyField( doc="""Amount dictatorwnames decided to keep for himself""", min=0, max=Constants.endowment, ) def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.payoff = self.kept p2.payoff = Constants.endowment - self.kept class Player(BasePlayer): name = models.StringField()