from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random, itertools doc = """ commons dilemma with three levels of uncertainty """ class Constants(BaseConstants): name_in_url = 'commons_dilemma_with_uncertainty' players_per_group = 4 num_rounds = 10 min_rr_uncertainty = 1.00 # minimum replenishment rate under uncertainty max_rr_uncertainty = 1.40 # maximum replenishment rate under uncertainty rr_certainty = (min_rr_uncertainty + max_rr_uncertainty)/2 r1_resource_size = c(300) class Subsession(BaseSubsession): def creating_session(self): for g in self.get_groups(): g.treatment = self.session.config['treatment'] class Group(BaseGroup): treatment = models.IntegerField() def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) p4 = self.get_player_by_id(4) p1.total_harvest = p2.total_harvest = p3.total_harvest = p4.total_harvest = p1.harvest + p2.harvest + p3.harvest + p4.harvest p1.min_rr_uncertainty = p2.min_rr_uncertainty = p3.min_rr_uncertainty = p4.min_rr_uncertainty = Constants.min_rr_uncertainty p1.max_rr_uncertainty = p2.max_rr_uncertainty = p3.max_rr_uncertainty = p4.max_rr_uncertainty = Constants.max_rr_uncertainty if p1.total_harvest > p1.t0_resource_size: p1.payoff = p2.payoff = p3.payoff = p4.payoff = c(0) p1.resource_depleted = p2.resource_depleted = p3.resource_depleted = p4.resource_depleted = True p1.t1_resource_size = p2.t1_resource_size = p3.t1_resource_size = p4.t1_resource_size = c(0) else: p1.payoff = p1.harvest p2.payoff = p2.harvest p3.payoff = p3.harvest p4.payoff = p4.harvest p1.resource_depleted = p2.resource_depleted = p3.resource_depleted = p4.resource_depleted = False p1.t1_resource_size = p2.t1_resource_size = p3.t1_resource_size = p4.t1_resource_size = (p1.t0_resource_size - p1.total_harvest) class Player(BasePlayer): t0_resource_size = models.CurrencyField() total_harvest = models.CurrencyField() t1_resource_size = models.CurrencyField() min_rr_uncertainty = models.FloatField() max_rr_uncertainty = models.FloatField() rr_resource = models.FloatField() harvest = models.CurrencyField() 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=["I will earn the number of points I took then", "I will earn zero points then", "I have not been informed about how many points I will earn then"], widget=widgets.RadioSelect) quiz_4 = models.CharField( choices=["I will earn the number of points I took then", "I will earn zero points then", "I have not been informed about how many points I will earn then"], widget=widgets.RadioSelect) uncertainty_check = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal)