from otree.api import * c = cu doc = '\nEach player decides if to call the police.' class C(BaseConstants): NAME_IN_URL = 'Police_Calling_Game_Original_Experiment' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 1 GENERAL_BENEFIT = cu(10) CALL_COST = cu(5) INSTRUCTIONS_TEMPLATE = 'Police_Calling_Game_Original_Experiment/instructions.html' 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 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(doc='Whether player volunteers', label='Do you want to call the police?') def victim(player: Player): group = player.group if player.id_in_group == 1: player.is_victim = True class Introduction(Page): form_model = 'player' class Decision(Page): form_model = 'player' form_fields = ['volunteer'] class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): form_model = 'player' page_sequence = [Introduction, Decision, ResultsWaitPage, Results]