from otree.api import * class C(BaseConstants): NAME_IN_URL = 'volunteer_4' PLAYERS_PER_GROUP = 3 NUM_OTHER_PLAYERS=PLAYERS_PER_GROUP-1 NUM_ROUNDS = 1 REWARD = cu(100) GENERAL_BENEFIT= cu(100) VOLUNTEER_COST = cu(40) NOVOLUNTEER=cu(0) INSTRUCTIONS_TEMPLATE = 'volunteer4/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): has_volunteer = models.BooleanField(initial=False) class Player(BasePlayer): is_volunteer = models.BooleanField() volunteer=models.BooleanField() is_notvolunteer = models.BooleanField() volunteer_id = models.IntegerField() notvolunteer_id= models.IntegerField() # PAGES class MyPage(Page): #form_model = 'player' #form_fields = ['is_volunteer'] @staticmethod def is_displayed(player: Player): group = player.group return not group.has_volunteer @staticmethod def live_method(player: Player, data): group = player.group # print('data is', data) if group.has_volunteer: #return #if data.get('volunteer'): #group.has_volunteer = True # mark all other players as non-volunteers for p in player.get_others_in_group(): p.payoff = C.REWARD p.is_volunteer = False # mark myself as a volunteer player.is_volunteer = True player.payoff = C.REWARD - C.VOLUNTEER_COST # broadcast to the group that the game is finished. return {0: dict(finished=True)} else: #if data.get('not_volunteer'): # goup.has_volunteer= False #mark all players as not volunteer player.payoff= C.NOVOLUNTEER return{0: dict(finished= True)} @staticmethod def live_method(player: Player, data): group = player.group if group.has_volunteer: return if data.get('volunteer'): group.has_volunteer = False p.payoff= C.NOVOLUNTEER # mark player as non-volunteer #if not group.has_volunteer: #return #player.payoff= C.NOVOLUNTEER class Results(Page): pass class waitpage(WaitPage): pass class Introduction(Page): pass page_sequence = [Introduction, MyPage, Results]