from otree.api import * import random doc = """ Behavioural Economics classroom experiments (LUT 2023) """ class C(BaseConstants): NAME_IN_URL = 'behavioural_econ_2' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 BALLET_ROLE = 'ballet' BOXING_ROLE = 'boxing' """ Experiments: 2. Strategic interaction: a) Stag-hunt game (SI1) b) Battle of the sexes (SI2) c) Chicken game (SI4) d) Prisoner's dilemma (SI5) """ class Subsession(BaseSubsession): pass def creating_session(subsession): if subsession.round_number == 1: for player in subsession.get_players(): participant = player.participant participant.treatment = subsession.session.config['TREATMENT'] # participant.treatment = "SI5" class Group(BaseGroup): pass class Player(BasePlayer): age = models.IntegerField(min=1920, max=2006) sex = models.StringField(widget=widgets.RadioSelect, choices=["Male", "Female", "I prefer not to say"]) SI1_answer = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, "STAG"], [1, "HARE"]], label="") SI1_combination = models.StringField() SI2_group = models.StringField() SI2_answer = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, 'BALLET'], [1, 'BOXING']], label="") SI2_combination = models.StringField() SI4_answer = models.IntegerField(widget=widgets.RadioSelect, choices=[[0, 'SWERVE'], [1, 'CONTINUE']], label="") SI4_combination = models.StringField() SI5_answer = models.IntegerField( label="Please choose if you want to cooperate or defect", choices=[ [0, "Defect"], [1, "Cooperate"], ] ) SI5_points = models.IntegerField() SI5_combination = models.StringField() # PAGES class Start(Page): pass class SI1(Page): def is_displayed(player: Player): return player.participant.treatment == "SI1" form_model = 'player' form_fields = ['SI1_answer'] class SI2(Page): def is_displayed(player: Player): return player.participant.treatment == "SI2" form_model = 'player' form_fields = ['SI2_answer'] def before_next_page(player: Player, timeout_happened): player.SI2_group = player.role class SI4(Page): def is_displayed(player: Player): return player.participant.treatment == "SI4" form_model = 'player' form_fields = ['SI4_answer'] class SI5(Page): def is_displayed(player: Player): return player.participant.treatment == "SI5" form_model = 'player' form_fields = ['SI5_answer'] class ResultsWaitPage(WaitPage): def is_displayed(player: Player): return player.participant.treatment == "SI1" or player.participant.treatment == "SI2" or player.participant.treatment == "SI4" class PrisonerWaitPage(WaitPage): def is_displayed(player: Player): return player.participant.treatment == "SI5" class Demographics(Page): form_model = 'player' form_fields = ['sex'] def before_next_page(player: Player, timeout_happened): if player.participant.treatment == "SI1": other = player.get_others_in_group() if player.SI1_answer == 0: for oth in other: if oth.SI1_answer == 0: player.payoff = 2 player.SI1_combination = "SS" else: player.payoff = 0 player.SI1_combination = "SH" else: for oth in other: if oth.SI1_answer == 0: player.payoff = 1 player.SI1_combination = "HS" else: player.payoff = 1 player.SI1_combination = "HH" if player.participant.treatment == "SI2": other = player.get_others_in_group() if player.SI2_answer == 0: for oth in other: if oth.SI2_answer == 0: player.payoff = 2 player.SI2_combination = "BalBal" else: player.payoff = 0 player.SI2_combination = "BalBox" else: for oth in other: if oth.SI2_answer == 0: player.payoff = 0 player.SI2_combination = "BoxBal" else: player.payoff = 1 player.SI2_combination = "BoxBox" if player.participant.treatment == "SI4": other = player.get_others_in_group() if player.SI4_answer == 0: for oth in other: if oth.SI4_answer == 0: player.payoff = 0 player.SI4_combination = "SS" else: player.payoff = -1 player.SI4_combination = "SC" else: for oth in other: if oth.SI4_answer == 0: player.payoff = 1 player.SI4_combination = "CS" else: player.payoff = -10 player.SI4_combination = "CC" if player.participant.treatment == "SI5": other = player.get_others_in_group() if player.SI5_answer == 0: for oth in other: if oth.SI5_answer == 0: player.SI5_points = 100 player.SI5_combination = "DD" else: player.SI5_points = 300 player.SI5_combination = "DC" else: for oth in other: if oth.SI5_answer == 0: player.SI5_points = 0 player.SI5_combination = "CD" else: player.SI5_points = 200 player.SI5_combination = "CC" class Final(Page): pass page_sequence = [ Start, SI1, SI2, SI4, SI5, ResultsWaitPage, PrisonerWaitPage, Demographics, Final ]