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 class PlayerBot(Bot): vh_list = [24.5, 37, 19, 23.5, 25] vl_list = [4.5, 5.5, 4, 5.0, 3.5] ph_list = [1037, 2589, 598, 913, 1155] pl_list = [101, 128, 80, 129, 54] def play_round(self): # Decide what to do for player 1 if self.player.id_in_group % 2 ==0 : yield (pages.Qual_Player1, {'vh': random.choice(self.vh_list), 'vl_guess_1':random.choice(self.vl_list), 'ph_guess_1': random.choice(self.ph_list), 'pl_guess_1':random.choice(self.pl_list)},) yield Submission(pages.Price, {'ph': random.choice(self.ph_list), 'pl':random.choice(self.pl_list)}, check_html=False) yield (pages.Results) if self.player.id_in_group % 2 != 0: yield (pages.Qual_Player2, {'vl':random.choice(self.vl_list), 'ph_guess_2':random.choice(self.ph_list), 'pl_guess_2':random.choice(self.pl_list)}) yield Submission(pages.Price, {'ph': random.choice(self.ph_list), 'pl': random.choice(self.pl_list)}, check_html=False) yield(pages.Results) # If you want the bot to play the optimal results in the control #def play_round(self): # # Decide what to do for player 1 # if self.player.id_in_group ==1: # yield (pages.Qual_Player1, {'vh': 11.12 + random.uniform(-1,1), 'v_guess_l':14.95/5}) # yield (pages.Results) # if self.player.id_in_group == 2: # yield (pages.Qual_Player2, {'vl': 1.06 + random.uniform(-1,1)}) # yield(pages.Results) # If you want the bots to play a random strategy #def play_round(self): # random_vh = random.uniform(0,500) # random_vl_guess = random.uniform(0, random_vh) # random_vl = random.uniform(0, random_vh) # print("what the bot selected") # print(random_vh) # print(random_vl_guess) # print(random_vl) # if self.player.id_in_group == 1: # yield (pages.Qual_Player1, {'vh': random_vh, 'v_guess_l': random_vl_guess}) # yield (pages.Results) # if self.player.id_in_group == 2: # yield (pages.Qual_Player2, {'vl': random_vl}) # yield (pages.Results) # If you want the bots to play a random strategy #def play_round(self): # random_vh = random.uniform(0,0.5) # random_vl_guess = random.uniform(0, random_vh) # random_vl = random.uniform(0, random_vh) # print("what the bot selected") # print(random_vh) # print(random_vl_guess) # print(random_vl) # if self.player.id_in_group == 1: # yield (pages.Qual_Player1, {'vh': random_vh, 'v_guess_l': random_vl_guess}) # yield (pages.Results) # if self.player.id_in_group == 2: # yield (pages.Qual_Player2, {'vl': random_vl}) # yield (pages.Results)