from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Wang Song' doc = """ Dictator Game for Group of 15 """ class Constants(BaseConstants): name_in_url = 'dictator15' players_per_group = 15 num_rounds = 1 #dollar_per_ecu = 0.05 endowment = 100 class Subsession(BaseSubsession): def creating_session(self): # use id_in_group to identify and match # stage 1: play as dictator # stage 2: play as dictatee for p in self.get_players(): if p.id_in_group == 15: p.stage1_dictatee_id = 1 else: p.stage1_dictatee_id = p.id_in_group + 1 if p.id_in_group == 1: p.stage2_dictator_id = 15 else: p.stage2_dictator_id = p.id_in_group - 1 class Group(BaseGroup): pass class Player(BasePlayer): stage1_keep = models.CurrencyField( choices=list(range(0, Constants.endowment+1)), #widget=widgets.Slider, ) stage2_receive = models.CurrencyField() stage1_dictatee_id = models.IntegerField() stage2_dictator_id = models.IntegerField() def set_payoff(self): p = self.group.get_player_by_id(self.stage2_dictator_id) self.stage2_receive = c(Constants.endowment - p.stage1_keep) self.payoff = self.stage1_keep + self.stage2_receive # )*Constants.dollar_per_ecu self.participant.vars['PayoffT1'] = self.payoff # self.participant.payoff = self.payoff # auto adding? (-Apr)