from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '' class Constants(BaseConstants): name_in_url = 'Task' players_per_group = None num_rounds = 600 class Subsession(BaseSubsession): def creating_session(self): import random print(random.random()) data = self.session.vars.get('data', []) # either gets the previous list, or if it doesn't exist (i.e. in round 1), gets a blank list data.append(random.choices([1,2,3,4,5,6,7,8,9], k = 6)) self.session.vars['data'] = data # randomize to treatments if self.round_number == 1: for p in self.get_players(): p.participant.vars['treatment'] = random.choice(['AI', 'human']) class Group(BaseGroup): pass class Player(BasePlayer): answer = models.IntegerField(blank=True, min=0) skip_button = models.StringField(blank=True, label='If you wish to end the test please type "Yes".') treatment = models.StringField() def set_payoffs(self): data = self.session.vars['data'] this_periods_randoms = data[self.round_number-1] # minus one to line up with zero index list_1 = [] list_1.append(this_periods_randoms[0]) list_1.append(this_periods_randoms[1]) list_1.append(this_periods_randoms[2]) list_2 = [] list_2.append(this_periods_randoms[3]) list_2.append(this_periods_randoms[4]) list_2.append(this_periods_randoms[5]) sum_1 = 0 sum_2 = 0 for num in list_1: sum_1 += int(num) for num in list_2: sum_2 += int(num) answer_1 = sum_1 + sum_2 answer_2 = sum_1 - sum_2 if sum(list_1) >= sum(list_2): correct_variable = answer_2 else: correct_variable = answer_1 if correct_variable == self.answer: result = 1 self.payoff = 1 return result else: result = 0 self.payoff = 0 return result