from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ Ultimatum game with two roles: the proposer and the responder. proposer makes an offer and the other either accepts or rejects. It includes a infromation about the amount of money to distribute for the proposer. In the latter stage, the second player is given a information from proposer about the amount of the money, which is true or not. """ class Constants(BaseConstants): name_in_url = 'UG_MT' players_per_group = 2 num_rounds = 1 instructions_template = 'UG_MT/Instructions.html' #endowment = c(random.randint(30,120)) payoff_if_rejected = c(0) offer_increment = c(10) #offer_choices = currency_range(0, 100, offer_increment) #offer_choices_count = len(offer_choices) #keep_give_amounts = [] #for offer in offer_choices: # keep_give_amounts.append((offer, endowment - offer)) class Subsession(BaseSubsession): def creating_session(self): # randomize to treatments # for g in self.get_groups(): # if 'treatment' in self.session.config: # g.use_strategy_method = self.session.config['use_strategy_method'] # else: # g.use_strategy_method = random.choice([True, False]) endowment =c(random.randint(30,120)) self.session.vars['endowment']=endowment def question(amount): return 'Would you accept an offer of {}?'.format(c(amount)) class Group(BaseGroup): use_strategy_method = models.BooleanField( doc="""Whether this group uses strategy method""" ) amount_offered = models.CurrencyField( verbose_name="how much do you want to offer to the responder?" ) amount_fortwo = models.CurrencyField( verbose_name="how much is the offered amount for you two?" ) # offer_choices = currency_range(0, amount_fortwo, 5) # offer_choices_count = len(offer_choices) # keep_give_amounts = [] # for offer in offer_choices: # keep_give_amounts.append((amount_offered, endowment - amount_offered)) amount_confidence = models.PositiveIntegerField( choices=[ [1, 'not confident at all'], [2, 'not confident'], [3, 'not sure'], [4, 'confident'], [5, 'very confident'], ] ) amount_trust = models.PositiveIntegerField( choices=[ [1, 'not trust at all'], [2, 'not trust'], [3, 'neutral'], [4, 'trust'], [5, 'trust a lot'], ] ) offer_accepted = models.BooleanField( doc="if offered amount is accepted (direct response method)" ) # for strategy method response_0 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(0)) response_10 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(10)) response_20 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(20)) response_30 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(30)) response_40 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(40)) response_50 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(50)) response_60 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(60)) response_70 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(70)) response_80 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(80)) response_90 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(90)) response_100 = models.BooleanField( widget=widgets.RadioSelectHorizontal, verbose_name=question(100)) def set_payoffs(self): p1, p2 = self.get_players() if self.offer_accepted: p1.payoff = endowment - self.amount_offered p2.payoff = self.amount_offered else: p1.payoff = Constants.payoff_if_rejected p2.payoff = Constants.payoff_if_rejected class Player(BasePlayer): results_happy = models.PositiveIntegerField( choices=[ [1, 'very unhappy'], [2, 'unhappy'], [3, 'not sure'], [4, 'happy'], [5, 'very happy'], ] )