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 = 'OneShot_PD_Results' players_per_group = 2 num_rounds = 1 betray_payoff = c(112) betrayed_payoff = c(25) both_cooperate_payoff = c(73) both_defect_payoff = c(42) bonus = c(40) instructions_template = 'OneShot_PD_Results/instructions.html' mywaitpage_template = 'OneShot_PD_Results/mywaitpage.html' instructions_shorter_template = 'OneShot_PD_Results/instructions_shorter.html' class Subsession(BaseSubsession): def Grouping_random(self): self.group_randomly() class Group(BaseGroup): def set_payoffs(self): for p in self.get_players(): p.set_payoff() class Player(BasePlayer): decision = models.StringField(choices=[['A', 'A'], ['B', 'B']], doc='This player s decision', widget=widgets.RadioSelect) def other_player(self): return self.get_others_in_group()[0] def set_payoff(self): payoff_matrix = dict( A=dict( A=Constants.both_cooperate_payoff, B=Constants.betrayed_payoff, ), B=dict( A=Constants.betray_payoff, B=Constants.both_defect_payoff, ), ) self.payoff = payoff_matrix[self.decision][self.other_player().decision]