from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random 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 = None num_rounds = 1 instructions_template = 'trust_task/Instructions.html' class Subsession(BaseSubsession): def creating_session(self): player_id = random.randint(0,1) #select player ID endowment = random.randint(2,10) reciprocity_return = endowment * random.randint(2,3) betrayal = reciprocity_return * 2 if player_id == 1: choice = True else: choice = random.choice([True,False]) self.session.vars['player_id'] = player_id self.session.vars['endowment'] = endowment self.session.vars['reciprocity_return'] = reciprocity_return self.session.vars['betrayal'] = betrayal self.session.vars['choice'] = choice pass class Group(BaseGroup): outcome = models.StringField() trust = models.BooleanField( choices=[ [False, 'Status quo'], [True, 'Trust'], ] ) reciprocity = models.BooleanField( choices=[ [False, 'Betrayal'], [True, 'Reciprocity'], ] ) pass class Player(BasePlayer): payoff = models.CurrencyField() pass