from otree.api import Currency as c, currency_range from . import pages from ._builtin import Bot from .models import Constants import random from otree.api import Submission # page_sequence = [ # Start, # Instructions, # # Introduction, # MplAutonomy, # # Results, # End # ] 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['mpla_switching_point'] # yield (pages.StartPage) if Constants.one_choice_per_page: if page == 1: yield (pages.Start) yield (pages.AutonomyChoice, {'first_autonomy_choice': random.randint(0, 2)}) if self.player.first_autonomy_choice == 2: yield (pages.AutonomyChoice2, {'second_autonomy_choice': random.randint(0, 1)}) else: pass if self.participant.vars['choice_neg'] == 0: # yield (pages.Instructions_p) indices = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_p'])][0] form_fields = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_p'])][1] if Constants.one_choice_per_page: if indices[page - 1] <= switching_point: # yield (pages.MplAutonomyPos, { # form_fields[page - 1]: 'A' # }) yield Submission(pages.MplAutonomyPos, { form_fields[page - 1]: 'A' }, check_html=False) else: # yield (pages.MplAutonomyPos, { # form_fields[page - 1]: 'B' # }) yield Submission(pages.MplAutonomyPos, { form_fields[page - 1]: 'B' }, check_html=False) else: decisions = [] for i in indices: if i <= switching_point: decisions.append('A') else: decisions.append('B') choices = zip(form_fields, decisions) # yield (pages.MplAutonomyPos, { # i: j for i, j in choices # }) yield Submission(pages.MplAutonomyPos, { i: j for i, j in choices }, check_html=False) elif self.participant.vars['choice_neg'] == 1: # yield (pages.Instructions_n) indices = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_n'])][0] form_fields = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_n'])][1] if Constants.one_choice_per_page: if indices[page - 1] <= switching_point: # yield (pages.MplAutonomyNeg, { # form_fields[page - 1]: 'A' # }) yield Submission(pages.MplAutonomyNeg, { form_fields[page - 1]: 'A' }, check_html=False) else: # yield (pages.MplAutonomyNeg, { # form_fields[page - 1]: 'B' # }) yield Submission(pages.MplAutonomyNeg, { form_fields[page - 1]: 'B' }, check_html=False) else: decisions = [] for i in indices: if i <= switching_point: decisions.append('A') else: decisions.append('B') choices = zip(form_fields, decisions) # yield (pages.MplAutonomyNeg, { # i: j for i, j in choices # }) yield Submission(pages.MplAutonomyPos, { i: j for i, j in choices }, check_html=False) else: if self.participant.vars['choice_neg'] == 0: # yield (pages.Instructions_p) indices = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_p'])][0] form_fields = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_p'])][1] if Constants.one_choice_per_page: if indices[page - 1] <= switching_point: # yield (pages.MplAutonomyPos, { # form_fields[page - 1]: 'A' # }) yield Submission(pages.MplAutonomyPos, { form_fields[page - 1]: 'A' }, check_html=False) else: # yield (pages.MplAutonomyPos, { # form_fields[page - 1]: 'B' # }) yield Submission(pages.MplAutonomyPos, { form_fields[page - 1]: 'B' }, check_html=False) else: decisions = [] for i in indices: if i <= switching_point: decisions.append('A') else: decisions.append('B') choices = zip(form_fields, decisions) # yield (pages.MplAutonomyPos, { # i: j for i, j in choices # }) yield Submission(pages.MplAutonomyPos, { i: j for i, j in choices }, check_html=False) elif self.participant.vars['choice_neg'] == 1: # yield (pages.Instructions_n) indices = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_n'])][0] form_fields = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_n'])][1] if Constants.one_choice_per_page: if indices[page - 1] <= switching_point: # yield (pages.MplAutonomyNeg, { # form_fields[page - 1]: 'A' # }) yield Submission(pages.MplAutonomyNeg, { form_fields[page - 1]: 'A' }, check_html=False) else: # yield (pages.MplAutonomyNeg, { # form_fields[page - 1]: 'B' # }) yield Submission(pages.MplAutonomyNeg, { form_fields[page - 1]: 'B' }, check_html=False) else: decisions = [] for i in indices: if i <= switching_point: decisions.append('A') else: decisions.append('B') choices = zip(form_fields, decisions) # yield (pages.MplAutonomyNeg, { # i: j for i, j in choices # }) yield Submission(pages.MplAutonomyPos, { i: j for i, j in choices }, check_html=False) # else: # yield (pages.AutonomyChoice2, {'second_autonomy_choice': random.randint(0, 1)}) # if self.player.second_autonomy_choice == 1: # yield (pages.Instructions_n) # elif self.player.second_autonomy_choice == 0: # yield (pages.Instructions_p) # else: # if self.player.participant.vars['choice_neg'] == 1: # # ------------------------------------------------------------------------------------------------------------ # # submit instructions page # ------------------------------------------------------------------------------------------------------------ # # if Constants.instructions: # if Constants.one_choice_per_page: # if page == 1: # yield (pages.Start) # yield (pages.Instructions) # yield (pages.ComprehensionCheck, {'comp_checkA': random.randint(0,1), # 'comp_checkB': random.randint(0,1)}) # yield (pages.ComprehensionCheckFail) # else: # yield (pages.StartPage) # ------------------------------------------------------------------------------------------------------------ # # make decisions # ------------------------------------------------------------------------------------------------------------ # # indices = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_n'])][0] # form_fields = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_n'])][1] # # if Constants.one_choice_per_page: # if indices[page - 1] <= switching_point: # yield (pages.MplAutonomyNeg, { # form_fields[page - 1]: 'A' # }) # else: # yield (pages.MplAutonomyNeg, { # 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.MplAutonomyNeg, { # i: j for i, j in choices # }) # # # # # # ------------------------------------------------------------------------------------------------------------ # # # make decisions # # ------------------------------------------------------------------------------------------------------------ # # else: # indices = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_p'])][0] # form_fields = [list(t) for t in zip(*self.player.participant.vars['mpla_choices_p'])][1] # # if Constants.one_choice_per_page: # if indices[page - 1] <= switching_point: # yield (pages.MplAutonomyPos, { # form_fields[page - 1]: 'A' # }) # else: # yield (pages.MplAutonomyPos, { # 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.MplAutonomyPos, { # i: j for i, j in choices # }) # # ------------------------------------------------------------------------------------------------------------ # # submit results page # ------------------------------------------------------------------------------------------------------------ # # if page == Constants.num_choices: # yield (pages.End) # else: # yield (pages.End) # if self.subsession.round_number == Constants.num_rounds: # yield(pages.End) # if Constants.results: # if Constants.one_choice_per_page: # if page == Constants.num_choices: # yield (pages.End) # else: # yield (pages.End) # #