from otree.api import * c = cu doc = 'This is a one-shot "Prisoner\'s Dilemma". The players are asked separately\nwhether they want to choose option A or B. Before they make their decision, they read a text about a biological topic. Their choices directly determine their payoffs.\n' class C(BaseConstants): NAME_IN_URL = 'Prisoner_Text2' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 PAYOFF_A = cu(1) PAYOFF_B = cu(0.7) PAYOFF_C = cu(0.3) PAYOFF_D = cu(0) INSTRUCTIONS_TEMPLATE = 'Prisoner_Text2/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass def set_payoffs(group: Group): for p in group.get_players(): set_payoff(p) class Player(BasePlayer): cooperate = models.BooleanField(choices=[[True, 'Cooperate'], [False, 'Defect']], doc='This player s decision', widget=widgets.RadioSelect) age = models.IntegerField(label='What is your age?') gender = models.StringField(choices=[['female', 'female'], ['male', 'male'], ['diverse', 'diverse']], label='What is your gender?') country = models.StringField(label='What is your country of residence?') religion = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Do you describe yourself as religious?') higher_instance = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Have you ever had an experience which convinced you of the extistence of God/Gods/comparable higher instances?') education = models.StringField(choices=[['Early childhood education (e.g. nursery)', 'Early childhood education (e.g. nursery)'], ['Primary education (e.g. elementary school)', 'Primary education (e.g. elementary school)'], ['School-leaving qualifications (e.g. high school, college, A-levels…)', 'School-leaving qualifications (e.g. high school, college, A-levels…)'], ['Bachelor or Master level education', 'Bachelor or Master level education'], ['Higher academic education', 'Higher academic education']], label='What is your level of education?') text = models.IntegerField(label='text') def other_player(player: Player): group = player.group return player.get_others_in_group()[0] def set_payoff(player: Player): payoff_matrix = { (False, True): C.PAYOFF_A, (True, True): C.PAYOFF_B, (False, False): C.PAYOFF_C, (True, False): C.PAYOFF_D, } other = other_player(player) player.payoff = payoff_matrix[(player.cooperate, other.cooperate)] class Introduction(Page): form_model = 'player' class Texts(Page): form_model = 'player' class Decision(Page): form_model = 'player' form_fields = ['cooperate'] class Demographic_questions(Page): form_model = 'player' form_fields = ['age', 'gender', 'country', 'religion', 'higher_instance', 'education'] page_sequence = [Introduction, Texts, Decision, Demographic_questions]