from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'control_group' PLAYERS_PER_GROUP = 5 NUM_ROUNDS = 1 GENERAL_BENEFIT = cu(10) VOLUNTEER_COST = cu(5) 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 p.id != 5]) # Exclude players with player ID 5 if group.num_volunteers > 0: baseline_amount = C.GENERAL_BENEFIT victim_payoff = 0 else: baseline_amount = cu(0) victim_payoff = -5 for p in players: if p.id != 5: # Exclude players with player ID 5 p.payoff = baseline_amount if p.volunteer: p.payoff -= C.VOLUNTEER_COST else: p.payoff = victim_payoff class Player(BasePlayer): volunteer = models.BooleanField(initial=False, label='Do you call the police?') class Introduction(Page): form_model = 'player' class Distribution_of_roles(Page): form_model = 'player' class Decision(Page): form_model = 'player' form_fields = ['volunteer'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group !=5 @staticmethod def before_next_page(player: Player, timeout_happened): group = player.group if player.id_in_group == 5: player.volunteer = False return player.skip_next_page() class MyWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): form_model = 'player' page_sequence = [Introduction, Distribution_of_roles, Decision, MyWaitPage, Results]