from otree.api import Currency as c, currency_range from . import pages from ._builtin import Bot from .models import Constants from otree.api import Submission import random """For testing the Programm with bots. """ class PlayerBot(Bot): def play_round(self): """with "yield" a page gets played or accepted by the bot. in {}- braces you can define what the bt should answer or decide (This must be defined!). For the vaccination decision a random number was generated to create random results of decisions. :return: """ if self.round_number == 1: yield (pages.Consent, {'consent': 1}) yield (pages.Instructions_1) yield (pages.Instructions_2) yield (pages.Instructions_3) yield (pages.Instructions_4) yield (pages.Instructions_5) rand_decision = random.random() #calculates random number if rand_decision > 0.5: #if random number is smaller than 0.5, bot decides for vaccination yield (pages.Decision, {'decision': 1}) else: #in every other case bot decides against vaccination yield (pages.Decision, {'decision': 0}) yield (pages.Results) if self.round_number == Constants.num_rounds: yield Submission(pages.Payoff_and_Debriefing, check_html=False) #for the last page yield-command must look like this to prevent error (bot searches for button #to continue, tht does not exist on this last page). pass