from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'Police_Experiment_Treatment2' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 1 NUM_OTHER_PLAYERS = 0 VOLUNTEER_COST = cu(0) GENERAL_BENEFIT = cu(10) CALL_COST = cu(5) class Subsession(BaseSubsession): pass class Group(BaseGroup): num_volunteers = models.IntegerField(initial=0) 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 victim_amount = 0 else: baseline_amount = cu(0) victim_amount = -5 for p in players: p.payoff = baseline_amount if p.id_in_group == 1: p.payoff = victim_amount if p.volunteer: if p.id_in_group != 1: p.payoff -= C.CALL_COST class Player(BasePlayer): volunteer = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label='Do you call the police?') def victim(player: Player): group = player.group if player.id_in_group == 1 : player.is_victim = True 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]