from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ STAGHUNT. Two players are asked separately whether they want to cooperate or defect. Their choices directly determine the payoffs. """ class Constants(BaseConstants): name_in_url = 'shl_3' players_per_group = 2 num_rounds = 20 instructions_template = 'staghunt_notamt/instructions.html' # payoff if 1 player defects and the other cooperates""", betray_payoff = c(9) betrayed_payoff = c(0) # payoff if both players cooperate or both defect both_cooperate_payoff = c(10) both_defect_payoff = c(7) class Subsession(BaseSubsession): #a = models.IntegerField(initial=0) #b = models.IntegerField(initial=0) #c = models.IntegerField(initial=0) #d = models.IntegerField(initial=0) #e = models.IntegerField(initial=0) #f = models.IntegerField(initial=0) #g = models.IntegerField(initial=0) #h = models.IntegerField(initial=0) def creating_session(self): self.group_randomly() #def creating_session(self): # my_list_1 = [1, 2, 3, 4] # my_list_2 = [5, 6, 7, 8] # self.session.vars['my_list'] = my_list_1 # self.session.vars['my_list_2'] = my_list_2 # self.a = random.choice(self.session.vars['my_list']) # self.session.vars['my_list'].remove(self.a) # self.b = random.choice(self.session.vars['my_list']) # self.session.vars['my_list'].remove(self.b) # self.c = random.choice(self.session.vars['my_list']) # self.session.vars['my_list'].remove(self.c) # self.d = random.choice(self.session.vars['my_list']) # self.session.vars['my_list'].remove(self.d) # self.e = random.choice(self.session.vars['my_list_2']) # self.session.vars['my_list_2'].remove(self.e) # self.f = random.choice(self.session.vars['my_list_2']) # self.session.vars['my_list_2'].remove(self.f) # self.g = random.choice(self.session.vars['my_list_2']) # self.session.vars['my_list_2'].remove(self.g) # self.h = random.choice(self.session.vars['my_list_2']) # self.session.vars['my_list_2'].remove(self.h) # new_structure = [[self.a, self.b], [self.c, self.d], [self.e, self.f], [self.g, self.h]] # self.set_group_matrix(new_structure) class Group(BaseGroup): pass class Player(BasePlayer): decision = models.StringField( choices=['Cooperate', 'Defect'], doc="""This player's decision""", widget=widgets.RadioSelect ) signals = models.StringField( choices=["orange_quatre.png", "dark_pink_star.png", "blue_diamond.png", "black_circle.png", "green_square.png", "yellow_triangle.png"], doc="""This player's signal""", widget=widgets.RadioSelect ) def buttons_table(self): self.participant.vars['button_list'] = ["orange_quatre.png", "dark_pink_star.png", "blue_diamond.png", "black_circle.png", "green_square.png", "yellow_triangle.png"] random.shuffle(self.participant.vars['button_list']) return self.participant.vars['button_list'] def other_player(self): return self.get_others_in_group()[0] def set_payoff(self): payoff_matrix = { 'Cooperate': { 'Cooperate': Constants.both_cooperate_payoff, 'Defect': Constants.betrayed_payoff }, 'Defect': { 'Cooperate': Constants.betray_payoff, 'Defect': Constants.both_defect_payoff } } self.payoff = payoff_matrix[self.decision][self.other_player().decision] #skill_answer = models.StringField(label="Your answer:")