from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) 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 = 2 num_rounds = 1 instructions_template = 'dictator/instructions.html' # Initial amount allocated to the dictator endowment = c(100) payoff_if_rejected = c(0) kept_increment = c(10) kept_choices = currency_range(0, endowment, kept_increment) kept_choices_count = len(kept_choices) class Subsession(BaseSubsession): def creating_session(self): self.group_randomly(fixed_id_in_group=True) class Player(BasePlayer): d_payoff = models.IntegerField() kept = models.CurrencyField(choices=Constants.kept_choices,label='Your offer:') def role(self): if self.id_in_group == 1: return 'Dictator' if self.id_in_group == 2: return 'Receiver_d' def other_player(self): return self.get_others_in_group()[0] class Group(BaseGroup): def set_payoffs(self): dictator = self.get_player_by_role('Dictator') receiver_d = self.get_player_by_role('Receiver_d') dictator.payoff = dictator.kept receiver_d.payoff = Constants.endowment - dictator.kept