from otree.api import Currency as c, currency_range, Submission from . import pages from ._builtin import Bot from .models import Constants from otree.api import expect import random class PlayerBot(Bot): cases = [#'consent_all', 'timeout', 'random'] # 'consent_1', 'consent_2', 'consent_3', 'consent_4', 'consent_5', 'consent_none'] def play_round(self): current_treatment = self.session.config['current_treatment'] if self.round_number == 1: dic = {'question1': Constants.expected_control_answer[0], 'question2': Constants.expected_control_answer[1], 'question3': Constants.expected_control_answer[2], 'question4': Constants.expected_control_answer[3], 'question5': Constants.expected_control_answer[4], 'question6': Constants.expected_control_answer[5], 'question7': Constants.expected_control_answer[6], 'question8': Constants.expected_control_answer[7], } if current_treatment == 2: dic['question9'] = Constants.expected_control_answer[8] elif current_treatment == 3: dic['question10'] = Constants.expected_control_answer[9] if self.case == 'timeout': yield Submission(pages.Instructions, dic, timeout_happened=True) else: yield pages.Instructions, dic current_choices = Constants.preferences[self.player.id_in_group] if self.case == 'random': random.shuffle(current_choices) print("The preferences of student " + str(self.participant.id_in_session) + " are " + str( current_choices) + ".") if current_treatment == 1: yield pages.Survey, {'first_choice': current_choices[0], 'second_choice': current_choices[1], 'third_choice': current_choices[2], 'fourth_choice': current_choices[3], 'fifth_choice': current_choices[4]} else: if self.case == 'consent_' + str(self.player.id_in_group) or self.case == 'consent_all': consent_val = 1 elif self.case == 'random': consent_val = random.randint(0, 1) else: consent_val = 0 yield pages.Survey, {'first_choice': current_choices[0], 'second_choice': current_choices[1], 'third_choice': current_choices[2], 'fourth_choice': current_choices[3], 'fifth_choice': current_choices[4], 'consent': consent_val} if self.case != 'random': if current_treatment != 1 and (self.case == 'consent_all' or self.case == 'consent_1'): expect(self.player.participant.vars['school_allocation'], ['E', 'B', 'D', 'C', 'A']) elif current_treatment != 1 and self.case == 'consent_4': expect(self.player.participant.vars['school_allocation'], ['E', 'A', 'D', 'B', 'C']) else: expect(self.player.participant.vars['school_allocation'], ['E', 'A', 'C', 'B', 'D']) yield pages.Outcome if self.round_number == Constants.num_rounds and 'timed_out' not in self.participant.vars: dic = {'gender': 0, 'age': 16, 'study': 0, 'truthful': 0} if current_treatment == 3 and 'tick_one_round' in self.participant.vars: dic['object_reason'] = 0 dic['object_other'] = 0 if current_treatment == 2 and 'tick_one_round' in self.participant.vars: dic['consent_reason'] = 0 dic['consent_other'] = 0 yield pages.Demographics, dic yield Submission(pages.Results, check_html=False) if self.round_number == Constants.num_rounds and 'timed_out' in self.participant.vars: yield Submission(pages.TimedOut, check_html=False)