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(60,120)) # endowment = c(115) # 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 question(amount): return 'Would you accept an offer of {}?'.format(c(amount)) # def creating_session(self): # for g in self.get_groups(): # g.endowment = c(random.randint(30,150)) def creating_session(self): for p in self.get_players(): p.endowment = c(random.randint(30,160)) class Group(BaseGroup): # self.endowment=c(random.randint(60,120)) # 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)) def set_payoffs(self): p1, p2 = self.get_players() # if self.offer_accepted: p1.payoff = 0 p2.payoff = 0 class Player(BasePlayer): endowment = models.CurrencyField() amount_offered = models.CurrencyField( min=1, max=140, verbose_name="how much do you want to offer to the responder?" ) amount_fortwo = models.CurrencyField( min=30, max=150, verbose_name="What amount do you want to tell to the responder that you have been given?" ) offer_accepted = models.BooleanField( doc="if offered amount is accepted (direct response method)" ) # else: # p1.payoff = 0 # p2.payoff = 0 # pain = models.PositiveIntegerField( # verbose_name='please rate the degree of pain you imagine you would feel in this scenario', # min=1, max=100, # widget=widgets.Slider(), # ) pain = models.IntegerField(widget=widgets.Slider(attrs={'step': '1', 'min': '0', 'max': '100'})) results_happy = models.IntegerField(widget=widgets.Slider(attrs={'step': '1', 'min': '0', 'max': '100'})) amount_confidence = models.IntegerField(widget=widgets.Slider(attrs={'step': '1', 'min': '0', 'max': '100'})) # results_happy = models.PositiveIntegerField( # verbose_name='please rate the degree of pain you imagine you would feel in this scenario', # min=1, max=100, # widget=widgets.Slider(), # ) # amount_confidence = models.PositiveIntegerField( # verbose_name='How confident are you that the responder will believe you', # min=1, max=100, # widget=widgets.Slider(), # )