from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random 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 = 'prisoner' players_per_group = 2 num_rounds = 5 instructions_template = 'prisoner/Instructions.html' # payoff if 1 player defects and the other cooperates""", betray_payoff = c(300) betrayed_payoff = c(0) # payoff if both players cooperate or both defect both_cooperate_payoff = c(200) both_defect_payoff = c(100) points_name = 'TJS' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): answer1 = models.IntegerField(label="How much money will you earn in this case?") answer2 = models.IntegerField(label="How much money each of you will earn") answer3 = models.IntegerField(label="How much money each of you will earn") pass age = models.IntegerField(label="How old are you? Please write your age and the year you were born?:") gender = models.StringField(choices=['Female', 'Male', 'Other'], label='What is your gender?') place = models.StringField( label='Where are you from?') education = models.StringField(choices=['High-School diploma', 'Bachelor Degree', 'Masters Degree', 'Doctor of Philosophy', ], label='What is your highest degree?') comment = models.StringField( label='Do you have any other comments?') cooperate = models.BooleanField( choices=[ [False, 'Defect'], [True, 'Cooperate'] ] ) def decision_label(self): if self.cooperate: return 'cooperate' return 'defect' def other_player(self): return self.get_others_in_group()[0] def set_payoff(self): payoff_matrix = { True: { True: Constants.both_cooperate_payoff, False: Constants.betrayed_payoff }, False: { True: Constants.betray_payoff, False: Constants.both_defect_payoff } } self.payoff = payoff_matrix[self.cooperate][self.other_player().cooperate]