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 = 'Skiptoend' players_per_group = 2 num_rounds = 1 betray_payoff = c(10) betrayed_payoff = c(0) both_cooperate_payoff = c(6) both_defect_payoff = c(2) instructions_template = 'Skiptoend/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_payoffs(self): for p in self.get_players(): p.set_payoff() def help_calculation(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) if p2.help == True: p1.payoff = p1.payoff + 10 p2.payoff = p2.payoff - 5 class Player(BasePlayer): decision = models.StringField(choices=[['Cooperate', 'Cooperate'], ['Defect', 'Defect']], doc='This player s decision', widget=widgets.RadioSelect) help = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label='', widget=widgets.RadioSelect) ManipulationCheck1 = models.StringField(blank=True, choices=[['Strongly Agree', 'Strongly Agree'], ['Agree', 'Agree'], ['Somewhat Agree', 'Somewhat Agree'], ['Neutral', 'Neutral'], ['Somewhat Disagree', 'Somewhat Disagree'], ['Disagree', 'Disagree'], ['Strongly Disagree', 'Strongly Disagree']], label='What was good for my partner was good for me:', widget=widgets.RadioSelectHorizontal) ManipulationCheck2 = models.StringField(blank=True, choices=[['Strongly Agree', 'Strongly Agree'], ['Agree', 'Agree'], ['Somewhat Agree', 'Somewhat Agree'], ['Neutral', 'Neutral'], ['Somewhat Disagree', 'Somewhat Disagree'], ['Disagree', 'Disagree'], ['Strongly Disagree', 'Strongly Disagree']], label='What was good for my partner was bad for me:', widget=widgets.RadioSelectHorizontal) Sex = models.StringField(blank=True, choices=[['Female', 'Female'], ['Male', 'Male'], ['Other', 'Other']], label='Sex:', widget=widgets.RadioSelectHorizontal) Age = models.IntegerField(blank=True, label='Age:', max=100, min=0) ManipulationCheck3 = models.StringField(blank=True, choices=[['Strongly Agree', 'Strongly Agree'], ['Agree', 'Agree'], ['Somewhat Agree', 'Somewhat Agree'], ['Neutral', 'Neutral'], ['Somewhat Disagree', 'Somewhat Disagree'], ['Disagree', 'Disagree'], ['Strongly Disagree', 'Strongly Disagree']], label='I depend on my partner', widget=widgets.RadioSelectHorizontal) ManipulationCheck4 = models.StringField(blank=True, choices=[['Strongly Agree', 'Strongly Agree'], ['Agree', 'Agree'], ['Somewhat Agree', 'Somewhat Agree'], ['Neutral', 'Neutral'], ['Somewhat Disagree', 'Somewhat Disagree'], ['Disagree', 'Disagree'], ['Strongly Disagree', 'Strongly Disagree']], label='I benefit from having a partner ', widget=widgets.RadioSelectHorizontal) HypotheticalHelp = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label="Imagine you were still playing the game and your partner only had a 10% chance of surviving into the next round, but you could pay 3ยข to give them a 90% chance of surviving. If they survived, you would both continue to the next round. If they did not survive, then there would be no more rounds because you'd have no one to interact with. Would you have been willing to pay 3 cents to increase their probability of survival from 10% to 90%?", widget=widgets.RadioSelectHorizontal) ErrorCheck = models.LongStringField(blank=True, label='Please let us know if anything was unclear about the game or its instructions ') ComprehensionOne = models.IntegerField(label='In a given round if both you and your partner choose to cooperate how many points do you earn?') ComprehensionTwo = models.IntegerField(label='In a given round if you choose to defect and your partner chooses to cooperate how many points do you earn?') ComprehensionThree = models.IntegerField(label='In a given round if both you and your partner choose to defect how many points do you earn?') 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] def help_player2(self): if self.id_in_group == 2 and help == True: self.participant.payoff = self.participant.payoff - 5 def help_player1(self): if self.id_in_group == 1 and help == True: self.participant.payoff = self.participant.payoff + 10