from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '\nThis is a one-shot "Prisoner\'s Dilemma". Two players are asked separately\nwhether they want to cooperate or defect. Their choices directly determine the\npayoffs.\n' class Constants(BaseConstants): name_in_url = 'NotInUse_OneShot_PD_wInstructions' players_per_group = 2 num_rounds = 2 betray_payoff = c(300) betrayed_payoff = c(0) both_cooperate_payoff = c(200) both_defect_payoff = c(100) expected_cooperators = 10 bonus = c(50) subsession_players = 20 num_groups = 10 instructions_template = 'NotInUse_OneShot_PD_wInstructions/instructions.html' class Subsession(BaseSubsession): def Grouping_fixedID(self): self.group_randomly(fixed_id_in_group=True) class Group(BaseGroup): def set_payoffs(self): for p in self.get_players(): p.set_payoff() class Player(BasePlayer): decision = models.StringField(choices=[['Cooperate', 'A'], ['Defect', 'B']], doc='This player s decision', widget=widgets.RadioSelect) beliefs = models.IntegerField(label='How many players out of 20 do you expect will cooperate?', max=20, min=0) decision2 = models.StringField(choices=[['Cooperate', 'A'], ['Defect', 'B']], widget=widgets.RadioSelect) beliefs2 = models.IntegerField(label='How many players out of 20 do you expect will cooperate?', max=20, min=0) def other_player(self): return self.get_others_in_group()[0] def set_payoff(self): payoff_matrix = dict( Cooperate=dict( Cooperate=Constants.both_cooperate_payoff, Defect=Constants.betrayed_payoff, ), Defect=dict( Cooperate=Constants.betray_payoff, Defect=Constants.both_defect_payoff ), ) self.payoff = payoff_matrix[self.decision][self.other_player().decision]