from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random doc = """ This is an 5-10 round n-player stag hung game with continuation probability of 0.45. """ class Constants(BaseConstants): name_in_url = 'stag_hunt' players_per_group = 2 for i in range(0, 5): x = random.uniform(0, 1) if x <= 0.45: i = i+1 else: break num_rounds = 5 + i instructions_template = 'stag_hunt/instructions.html' result_wait_template = 'stage_hunt_game/MyWaitPage.html' stag_match_payoff = c(4) stag_mismatch_payoff = c(0) h_1_hare_payoff = c(1) class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: self.group_randomly() else: self.group_like_round(1) if self.round_number == 1: paying_round = random.randint(1, Constants.num_rounds) self.session.vars['paying_round'] = paying_round class Group(BaseGroup): # This sets value of X in the payoff given the round def h_2_hare_payoff(self): if self.round_number <= 3: h_2_hare_payoff = c(2) else: h_2_hare_payoff = c(3) return h_2_hare_payoff # This sets payoffs based on the player choices def set_payoffs(self): h_1 = self.get_player_by_role('Hunter_1') h_2 = self.get_player_by_role('Hunter_2') if h_1.decision == 'hare' and h_2.decision == 'hare': h_1.payoff = Constants.h_1_hare_payoff # This is the standard payoff for choosing row 2 for player 1 h_2.payoff = self.h_2_hare_payoff() # This is the dynamic payoff for choosing column 2 for player 2 else: if h_1.decision == 'hare' and h_2.decision == 'stag': h_1.payoff = Constants.h_1_hare_payoff # Player 1 chooses row 2 h_2.payoff = Constants.stag_mismatch_payoff # Player 2 chooses column 1 else: if h_1.decision == 'stag' and h_2.decision == 'hare': h_1.payoff = Constants.stag_mismatch_payoff # Player 1 chooses row 1 h_2.payoff = self.h_2_hare_payoff() # Player 2 chooses column 2 else: h_1.payoff = Constants.stag_match_payoff # Player 1 chooses row 1 h_2.payoff = Constants.stag_match_payoff # Player 2 chooses column 1 class Player(BasePlayer): decision = models.StringField( choices=['stag', 'hare'], doc="""This player's decision is either stag or hare""", widget=widgets.RadioSelect, ) def other_player(self): return self.get_others_in_group()[0] def role(self): if self.id_in_group == 1: return 'Hunter_1' if self.id_in_group == 2: return 'Hunter_2' station_number = models.IntegerField(min=1, max=30) age = models.IntegerField(min=18, max=100) gender = models.StringField( choices=['Male', 'Female', 'Other'], widget=widgets.RadioSelectHorizontal ) race = models.StringField( choices=[ 'American Indian or Alaska Native', 'Asian', 'Black or African American', 'Hispanic or Latino', 'Native Hawaiian or Other Pacific Islander', 'White' ], widget=widgets.RadioSelect ) major = models.StringField( choices=[ 'Aerospace Engineering, B.S.', 'African American Studies, B.A.', 'Anthropology, B.A.', 'Applied Physics', 'Art, B.A.', 'Art History, B.A.', 'Asian American Studies, B.A.', 'Biochemistry and Molecular Biology, B.S.', 'Biological Sciences, B.S.', 'Biology/Education, B.S.', 'Biomedical Engineering, B.S.', 'Biomedical Engineering: Premedical, B.S.', 'Business Administration, B.A.', 'Business Economics, B.A.', 'Business Information Management, B.S.', 'Chemical Engineering, B.S.', 'Chemistry, B.S.', 'Chicano/Latino Studies, B.A.', 'Chinese Studies, B.A.', 'Civil Engineering, B.S.', 'Classics, B.A.', 'Cognitive Sciences, B.S.', 'Comparative Literature, B.A.', 'Computer Engineering, B.S.', 'Computer Game Science, B.S.', 'Computer Science, B.S.', 'Computer Science and Engineering, B.S.', 'Criminology, Law and Society, B.A.', 'Dance, B.A., B.F.A.', 'Data Science, B.S.', 'Developmental and Cell Biology, B.S.', 'Drama, B.A.', 'Earth System Science, B.S.', 'East Asian Cultures, B.A.', 'Ecology and Evolutionary Biology, B.S.', 'Economics, B.A.', 'Education Sciences, B.A.', 'Electrical Engineering, B.S.', 'Engineering, B.S.', 'English, B.A.', 'Environmental Engineering, B.S.', 'Environmental Science, B.A.', 'Environmental Science and Policy, B.A.', 'European Studies, B.A.', 'Exercise Sciences, B.S.', 'Film and Media Studies, B.A.', 'French, B.A.', 'Gender and Sexuality Studies, B.A.', 'Genetics, B.S.', 'German Studies, B.A.', 'Global Cultures, B.A.', 'Global Middle East Studies, B.A.', 'History, B.A.', 'Human Biology, B.S.', 'Informatics, B.S.', 'Information and Computer Science, B.S.', 'International Studies, B.A.', 'Japanese Language and Literature, B.A.', 'Korean Literature and Culture, B.A.', 'Language Science, B.A.', 'Literary Journalism, B.A.', 'Materials Science and Engineering, B.S.', 'Mathematics, B.S.', 'Mechanical Engineering, B.S.', 'Microbiology and Immunology, B.S.', 'Music, B.A., B.Mus.', 'Music Theatre, B.F.A.', 'Neurobiology, B.S.', 'Nursing Science, B.S.', 'Pharmaceutical Sciences, B.S.', 'Philosophy, B.A.', 'Physics, B.S.', 'Political Science, B.A.', 'Psychology, B.A.', 'Psychological Science, B.A.', 'Public Health Policy, B.A.', 'Public Health Sciences, B.S.', 'Quantitative Economics, B.A.', 'Religious Studies, B.A.', 'Social Ecology, B.A.', 'Social Policy and Public Service, B.A.', 'Sociology, B.A.', 'Software Engineering, B.S.', 'Spanish, B.A.', 'Urban Studies, B.A.', 'Undeclared', 'Other' ] ) role_check = models.StringField( choices=[ 'Hunter 1', 'Hunter 2' ], widget=widgets.RadioSelectHorizontal ) risk_self_assess = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], label='''How do you see yourself: Are you in general a person who takes risk or do you try to evade risks? Please self‐grade your choice. The grades run from 0: “not at all prepared to take risk” to 10: “very much prepared to take risk”.''', widget=widgets.RadioSelectHorizontal ) lottery_question_1 = models.IntegerField( min=0, label=''' Suppose in a lottery game, the possibility to win 1,000 dollars is 10%, then how much would you pay at most to buy a lottery ticket? ''' ) lottery_reserve_question = models.IntegerField( min=0, label=''' Now we change the conditions of the choice. Suppose you are offered 100 dollars in cash. Instead, however, you may choose a lottery ticket. The lottery has a prize of 2000 dollars, but the probability to win has not yet been determined. How high should this probability be at least for you to take the lottery ticket rather than the 100 dollar in cash? ''' )