from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ Each player decides if to free ride or to volunteer from which all will benefit. See: Diekmann, A. (1985). Volunteer's dilemma. Journal of Conflict Resolution, 605-610. """ class Constants(BaseConstants): name_in_url = 'volunteer_dilemma' players_per_group = 3 num_rounds = 1 instructions_template = 'volunteer_dilemma/Instructions.html' num_other_players = players_per_group - 1 # """Payoff for each player if at least one volunteers""" general_benefit = c(10) # """Cost incurred by volunteering player""" volunteer_cost = c(4) class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_payoffs(self): if any(p.volunteer for p in self.get_players()): baseline_amount = Constants.general_benefit else: baseline_amount = c(0) for p in self.get_players(): p.payoff = baseline_amount if p.volunteer: p.payoff -= Constants.volunteer_cost class Player(BasePlayer): ppnr = models.IntegerField(verbose_name='What is your participant number (= participant nummer dat op het papiertje staat)?') name = models.StringField(verbose_name='What is your first name?') age = models.PositiveIntegerField( verbose_name='What is your age (in years)?', min=13, max=125) gender = models.CharField(verbose_name='What is your gender?') study = models.CharField(verbose_name='What do you study?') treatment = models.IntegerField() volunteer = models.BooleanField( doc="""Whether player volunteers""", ) 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) condition = models.CharField() role_saved = models.StringField() quiz_1 = models.CharField( choices=["1 Person", "2 Persons", "3 Persons", "4 Persons"], widget=widgets.RadioSelect) quiz_2 = models.CharField( choices=["5 point", "10 points", "15 points", "20 points"], widget=widgets.RadioSelect) quiz_3 = models.CharField( choices=["Then no one will keep any points.", "Then all group members will keep their points.", "I have not been informed about what will happen then."], widget=widgets.RadioSelect) quiz_4 = models.CharField( choices=["Then no one will keep any points.", "Then all group members will keep their points.", "I have not been informed about what will happen then."], widget=widgets.RadioSelect)