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 = 'sh_2' players_per_group = 2 num_rounds = 20 instructions_template = 'staghunt/instructions.html' # payoff if 1 player defects and the other cooperates""", betray_payoff = c(900) betrayed_payoff = c(0) # payoff if both players cooperate or both defect both_cooperate_payoff = c(1000) both_defect_payoff = c(700) class Subsession(BaseSubsession): def creating_session(self): self.group_randomly(fixed_id_in_group=True) 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=["button1.png", "button2.png"], doc="""This player's signal""", widget=widgets.RadioSelect ) def buttons_table(self): self.participant.vars['button_list'] = ["button1.png", "button2.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:")