from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ Discount Choice Game """ class Constants(BaseConstants): name_in_url = 'discount_choice' players_per_group = 2 num_rounds = 10 instructions_template = 'discount_choice/instructions.html' # payoff if 1 player defects and the other cooperates""", betray_payoff = c(60) betrayed_payoff = c(20) # payoff if both players cooperate or both defect both_cooperate_payoff = c(45) both_defect_payoff = c(30) class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_payoffs(self): for p in self.get_players(): p.set_payoff() class Player(BasePlayer): decision = models.StringField( choices=[['Low Discount', 'Low Discount'], ['High Discount', 'High Discount']], 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( Low_Discount=dict( Low_Discount=Constants.both_cooperate_payoff, High_Disocunt=Constants.betrayed_payoff, ), High_Discount=dict( Low_Discount=Constants.betray_payoff, High_Dicount=Constants.both_defect_payoff ), ) self.payoff = payoff_matrix[self.decision][self.other_player().decision]