from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'Police_Experiment_Controll_Group' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 1 GENERAL_BENEFIT = cu(10) VOLUNTEER_COST = cu(5) NUM_OTHER_PLAYERS = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): num_volunteers = models.IntegerField() def set_payoffs(group: Group): players = group.get_players() group.num_volunteers = sum([p.volunteer for p in players]) if group.num_volunteers > 0: baseline_amount = C.GENERAL_BENEFIT else: baseline_amount = cu(0) for p in players: p.payoff = baseline_amount if p.volunteer: p.payoff -= C.VOLUNTEER_COST class Player(BasePlayer): volunteer = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label='Do you call the police?') class Instructions(Page): form_model = 'player' class Decision(Page): form_model = 'player' form_fields = ['volunteer'] class MyWaitPage(WaitPage): after_all_players_arrive = set_payoffs title_text = 'WaitPage' body_text = 'Please wait until the other players have made a decision.' class Results(Page): form_model = 'player' page_sequence = [Instructions, Decision, MyWaitPage, Results]