from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ This is a standard 2-player trust game where the amount sent by player 1 gets tripled. The trust game was first proposed by Berg, Dickhaut, and McCabe (1995) . """ class Constants(BaseConstants): name_in_url = 'trust' players_per_group = 2 num_rounds = 1 instructions_template = 'trust/instructions.html' # Initial amount allocated to each player endowment = c(200) multiplier = 3 offer_increment = c(10) offer_choices = currency_range(0, endowment, offer_increment) offer_choices_count = len(offer_choices) return_choices_10 = currency_range(0, 10*multiplier, offer_increment) return_choices_20 = currency_range(0, 20*multiplier, offer_increment) return_choices_30 = currency_range(0, 30*multiplier, offer_increment) return_choices_40 = currency_range(0, 40*multiplier, offer_increment) return_choices_50 = currency_range(0, 50*multiplier, offer_increment) return_choices_60 = currency_range(0, 60*multiplier, offer_increment) return_choices_70 = currency_range(0, 70*multiplier, offer_increment) return_choices_80 = currency_range(0, 80*multiplier, offer_increment) return_choices_90 = currency_range(0, 90*multiplier, offer_increment) return_choices_100 = currency_range(0, 100*multiplier, offer_increment) return_choices_110 = currency_range(0, 110*multiplier, offer_increment) return_choices_120 = currency_range(0, 120*multiplier, offer_increment) return_choices_130 = currency_range(0, 130*multiplier, offer_increment) return_choices_140 = currency_range(0, 140*multiplier, offer_increment) return_choices_150 = currency_range(0, 150*multiplier, offer_increment) return_choices_160 = currency_range(0, 160*multiplier, offer_increment) return_choices_170 = currency_range(0, 170*multiplier, offer_increment) return_choices_180 = currency_range(0, 180*multiplier, offer_increment) return_choices_190 = currency_range(0, 190*multiplier, offer_increment) return_choices_200 = currency_range(0, 200*multiplier, offer_increment) class Subsession(BaseSubsession): def creating_session(self): self.group_randomly(fixed_id_in_group=True) class Player(BasePlayer): trust_payoff = models.IntegerField() sent_amount_trustor = models.CurrencyField(choices=Constants.offer_choices,label='Your offer:') sent_back_amount = models.CurrencyField() sent_back_amount_10 = models.CurrencyField(choices=Constants.return_choices_10,label='If 10:') sent_back_amount_20 = models.CurrencyField(choices=Constants.return_choices_20,label='If 20:') sent_back_amount_30 = models.CurrencyField(choices=Constants.return_choices_30,label='If 30:') sent_back_amount_40 = models.CurrencyField(choices=Constants.return_choices_40,label='If 40:') sent_back_amount_50 = models.CurrencyField(choices=Constants.return_choices_50,label='If 50:') sent_back_amount_60 = models.CurrencyField(choices=Constants.return_choices_60,label='If 60:') sent_back_amount_70 = models.CurrencyField(choices=Constants.return_choices_70,label='If 70:') sent_back_amount_80 = models.CurrencyField(choices=Constants.return_choices_80,label='If 80:') sent_back_amount_90 = models.CurrencyField(choices=Constants.return_choices_90,label='If 90:') sent_back_amount_100 = models.CurrencyField(choices=Constants.return_choices_100,label='If 100:') sent_back_amount_110 = models.CurrencyField(choices=Constants.return_choices_110,label='If 110:') sent_back_amount_120 = models.CurrencyField(choices=Constants.return_choices_120,label='If 120:') sent_back_amount_130 = models.CurrencyField(choices=Constants.return_choices_130,label='If 130:') sent_back_amount_140 = models.CurrencyField(choices=Constants.return_choices_140,label='If 140:') sent_back_amount_150 = models.CurrencyField(choices=Constants.return_choices_150,label='If 150:') sent_back_amount_160 = models.CurrencyField(choices=Constants.return_choices_160,label='If 160:') sent_back_amount_170 = models.CurrencyField(choices=Constants.return_choices_170,label='If 170:') sent_back_amount_180 = models.CurrencyField(choices=Constants.return_choices_180,label='If 180:') sent_back_amount_190 = models.CurrencyField(choices=Constants.return_choices_190,label='If 190:') sent_back_amount_200 = models.CurrencyField(choices=Constants.return_choices_200,label='If 200:') def sent_back_amount_max(self): return self.sent_amount_trustor * Constants.multiplier def role(self): if self.id_in_group == 1: return 'Trustor' if self.id_in_group == 2: return 'Trustee' def other_player(self): return self.get_others_in_group()[0] class Group(BaseGroup): def set_payoffs(self): trustor = self.get_player_by_role('Trustor') trustee = self.get_player_by_role('Trustee') trustee.sent_back_amount = getattr(trustee, 'sent_back_amount_{}'.format(int(trustor.sent_amount_trustor))) trustor.payoff = Constants.endowment - trustor.sent_amount_trustor + trustee.sent_back_amount trustee.payoff = trustor.sent_amount_trustor * Constants.multiplier - trustee.sent_back_amount