from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'prisoners' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 instructions_template = 'prisoner/instructions.html' betray_payoff = cu(300) betrayed_payoff = cu(0) both_cooperate_payoff = cu(200) both_defect_payoff = cu(100) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): decision = models.StringField( choices=[['Cooperate', 'Cooperate'], ['Defect', 'Defect']], doc="""This player's decision""", widget=widgets.RadioSelect, ) # FUNCTIONS def set_payoffs(group: Group): for p in group.get_players(): set_payoff(p) def other_player(player: Player): return player.get_others_in_group()[0] def set_payoff(player: Player): 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 ), ) player.payoff = payoff_matrix[player.decision][other_player(player).decision] # PAGES class Introduction(Page): timeout_seconds = 100 class Decision(Page): form_model = 'player' form_fields = ['decision'] class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): @staticmethod def vars_for_template(player: Player): me = player opponent = other_player(me) return dict( my_decision=me.decision, opponent_decision=opponent.decision, same_choice=me.decision == opponent.decision, ) page_sequence = [Introduction, Decision, ResultsWaitPage, Results]