from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random itertools doc = """ This anticommons game involves 3 sellers. The sellers each own one lottery ticket, which they can sell to the buyer (i.e., the experimenter). However, they will only sell their tickets if the collective asking price is lower than the offer of the buyer. There are three levels of uncertainty regarding the buyer's offer (no vs low vs high). """ class Constants(BaseConstants): name_in_url = 'anticommons_uncertainty' players_per_group = 3 # if you change this, also change the quiz question about number of players!!! num_rounds = 3 # if you change this, also change the quiz question about number of rounds!!! value_certainty = c(400) min_value_lowuncertainty = c(300) max_value_lowuncertainty = c(500) min_value_highuncertainty = c(200) max_value_highuncertainty = c(600) class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: for g in self.get_groups(): seller1 = g.get_player_by_id(1) seller2 = g.get_player_by_id(2) seller3 = g.get_player_by_id(3) seller1.value_certainty = seller2.value_certainty = seller3.value_certainty = Constants.value_certainty seller1.value_lowuncertainty = seller2.value_lowuncertainty = seller3.value_lowuncertainty = random.randint(Constants.min_value_lowuncertainty, Constants.max_value_lowuncertainty) seller1.value_highuncertainty = seller2.value_highuncertainty = seller3.value_highuncertainty = random.randint(Constants.min_value_highuncertainty, Constants.max_value_highuncertainty) seller1.participant.vars['order'] = seller2.participant.vars['order'] = seller3.participant.vars['order'] = random.choice([1, 2, 3, 4, 5, 6]) class Group(BaseGroup): def set_payoffs(self): seller1 = self.get_player_by_id(1) seller2 = self.get_player_by_id(2) seller3 = self.get_player_by_id(3) # calculate certainty payoffs if seller1.certainty_WTA + seller2.certainty_WTA + seller3.certainty_WTA <= seller1.value_certainty: seller1.certainty_payoff = seller1.certainty_WTA seller2.certainty_payoff = seller2.certainty_WTA seller3.certainty_payoff = seller3.certainty_WTA seller1.certainty_sell = seller2.certainty_sell = seller3.certainty_sell = True else: seller1.certainty_payoff = seller2.certainty_payoff = seller3.certainty_payoff = c(0) seller1.certainty_sell = seller2.certainty_sell = seller3.certainty_sell = False # calculate lowuncertainty payoffs if seller1.lowuncertainty_WTA + seller2.lowuncertainty_WTA + seller3.lowuncertainty_WTA <= seller1.value_lowuncertainty: seller1.lowuncertainty_payoff = seller1.lowuncertainty_WTA seller2.lowuncertainty_payoff = seller2.lowuncertainty_WTA seller3.lowuncertainty_payoff = seller3.lowuncertainty_WTA seller1.lowuncertainty_sell = seller2.lowuncertainty_sell = seller3.lowuncertainty_sell = True else: seller1.lowuncertainty_payoff = seller2.lowuncertainty_payoff = seller3.lowuncertainty_payoff = c(0) seller1.lowuncertainty_sell = seller2.lowuncertainty_sell = seller3.lowuncertainty_sell = False # calculate highuncertainty payoffs if seller1.highuncertainty_WTA + seller2.highuncertainty_WTA + seller3.highuncertainty_WTA <= seller1.value_highuncertainty: seller1.highuncertainty_payoff = seller1.highuncertainty_WTA seller2.highuncertainty_payoff = seller2.highuncertainty_WTA seller3.highuncertainty_payoff = seller3.highuncertainty_WTA seller1.highuncertainty_sell = seller2.highuncertainty_sell = seller3.highuncertainty_sell = True else: seller1.highuncertainty_payoff = seller2.highuncertainty_payoff = seller3.highuncertainty_payoff = c(0) seller1.highuncertainty_sell = seller2.highuncertainty_sell = seller3.highuncertainty_sell = False class Player(BasePlayer): treatment = models.IntegerField() treatmentname = models.StringField() order = models.IntegerField() quiz_1 = models.CharField( choices=["1 participant", "2 participants", "3 participants", "4 participants"], widget=widgets.RadioSelect) quiz_2 = models.CharField( choices=["10 rounds", "20 rounds", "30 rounds", "40 rounds"], widget=widgets.RadioSelect) quiz_3 = models.CharField( choices=["The Buyer will then not earn a monetary bonus.", "The Buyer will then earn a monetary bonus of 20 points.", "I have not been informed about how many points the Buyer will earn then."], widget=widgets.RadioSelect) quiz_4 = models.CharField( choices=["The Buyer will then not earn a monetary bonus.", "The Buyer will then earn a monetary bonus of 20 points.", "I have not been informed about how many points the Buyer will earn then."], widget=widgets.RadioSelect) quiz_5 = models.CharField( choices=["That Seller will then earn the number of points he/she asked for his/her part of the puzzle.", "That Seller will then earn zero points in that round.", "I have not been informed about how many points that Seller will earn then."], widget=widgets.RadioSelect) quiz_6 = models.CharField( choices=["That Seller will then earn the number of points he/she asked for his/her part of the puzzle.", "That Seller will then earn zero points in that round.", "I have not been informed about how many points that Seller will earn then."], widget=widgets.RadioSelect) motive_1 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) motive_2 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) motive_3 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) motive_4 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) motive_5 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) motive_6 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) motive_7 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) motive_8 = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) value_certainty = models.CurrencyField() value_lowuncertainty = models.CurrencyField() value_highuncertainty = models.CurrencyField() certainty_WTA = models.CurrencyField( min=0, max=Constants.value_certainty ) lowuncertainty_WTA = models.CurrencyField( min=0, max=Constants.max_value_lowuncertainty ) highuncertainty_WTA = models.CurrencyField( min=0, max=Constants.max_value_highuncertainty ) certainty_payoff = models.CurrencyField() lowuncertainty_payoff = models.CurrencyField() highuncertainty_payoff = models.CurrencyField() sell = models.BooleanField()