from otree.api import Currency as c, currency_range from . import pages from ._builtin import Bot from .models import Constants import random # ********************************************************************************************************************** # *** BOT # ********************************************************************************************************************** class PlayerBot(Bot): def play_round(self): # define page as round_number page = self.subsession.round_number # get bot's switching point switching_point = self.player.participant.vars['mpl_switching_point'] # ------------------------------------------------------------------------------------------------------------ # # submit instructions page # ------------------------------------------------------------------------------------------------------------ # # if Constants.instructions: # if Constants.one_choice_per_page: # if page == 1: # yield (pages.Instructions) # else: # yield (pages.Instructions) # ------------------------------------------------------------------------------------------------------------ # # submit P5BisRiskyTask page # ------------------------------------------------------------------------------------------------------------ # yield (pages.P7BisBienvenue, { }) yield (pages.P7Instructions, { }) # yield (pages.P8qc, { # 'qc_1':4, # 'qc_2':8, # 'qc_3':19.25, # 'qc_4':0.5, # }) # ------------------------------------------------------------------------------------------------------------ # # make decisions # ------------------------------------------------------------------------------------------------------------ # indices = [list(t) for t in zip(*self.player.participant.vars['mpl_choices'])][0] form_fields = [list(t) for t in zip(*self.player.participant.vars['mpl_choices'])][1] if Constants.one_choice_per_page: if indices[page - 1] <= switching_point: yield (pages.P9Decision, { form_fields[page - 1]: 'A' }) else: yield (pages.P9Decision, { form_fields[page - 1]: 'B' }) else: decisions = [] for i in indices: if i <= switching_point: decisions.append('A') else: decisions.append('B') choices = zip(form_fields, decisions) yield (pages.P9Decision, { i: j for i, j in choices }) ################################# # yield (pages.P10Survey, { # 'survey_1':random.randint(0, 10), # })