from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = """ This is a one-shot "Prisoner's Dilemma". Two players are asked separately whether they want to cooperate or defect. Their choices directly determine the payoffs. """ class Constants(BaseConstants): name_in_url = 'class_prisoners_dilemma' players_per_group = 2 num_rounds = 1 instructions_template = 'class_prisoners_dilemma/Instructions.html' # payoff if 1 player defects and the other cooperates""", betray_payoff = c(0) betrayed_payoff = c(-20) # payoff if both players cooperate or both defect both_cooperate_payoff = c(-1) both_defect_payoff = c(-8) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): econumber=models.StringField() decision = models.StringField( choices=['Confess', 'Remain Silent'], 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 = { 'Confess': { 'Confess': Constants.both_defect_payoff, 'Remain Silent': Constants.betray_payoff }, 'Remain Silent': { 'Confess': Constants.betrayed_payoff, 'Remain Silent': Constants.both_cooperate_payoff } } self.payoff = payoff_matrix[self.decision][self.other_player().decision]