from otree.api import * 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 C(BaseConstants): NAME_IN_URL = 'volunteer_dilemma6' 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 = cu(100) # """Cost incurred by volunteering player""" VOLUNTEER_COST = cu(40) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): invest= models.BooleanField(choices=((True, 'Ja'),(False,'Nej')), label='Do you wish to volunteer?', doc="""Whether player volunteers""", required=True,) # PAGES class MyPage(Page): form_model = 'player' form_fields = ['invest'] @staticmethod def live_method(player, data): group = player.group [other] = player.get_others_in_group() t=data['invest'] if t == True: #if data['decision_type']="invest": for p in player.get_others_in_group(): p.payoff = C.REWARD p.invest = False player.invest = True player.payoff = C.REWARD - C.VOLUNTEER_COST return {0:dict(finished=True)} if t == False: if class Introduction(Page): pass class Decision(Page): pass class Results(Page): pass page_sequence = [Introduction,MyPage,Results]