oTree Forum >

HOW TO IMPLEMENT A synchronous WAITPAGE FUNCTION FOR BOTS ?

#1 by utilisaction

Hello everyone,

I am trying to implement bots in an OTree experiment with iterative rounds. In each round, there are multiple WaitPages and Page.

First question : HOW TO IMPLEMENT A WAITPAGE FUNCTION FOR BOTS ? My WaitPage assigns different values for each player according to a function run over all the players (simultaneously).
OTree does not record variables assigned to the player in WaitPage1 for the bots whereas it works for regular players. 
My WaitPage1 runs a function over the object group called Group within which there is a loop for to implement an attribute called attribut over each player. This function can be run only one time : it randomly assign a player to an other player. 
Then, according to the result of the global function over the group an attribute specific to each player is implemented within the loop :  
for player in group.get_players():

Problem : in WaitPage1,  
        for player in self.group.get_players():
            print('Accord', player.attribut)
            assert player.attribut is None, "Attribute is not correctly defined"

For the first bot player, WaitPage works but for the second, it fails. 
MY QUESTION IS: How to implement a function over all bot players (run only one time), which defines a different variable for each player ? 
Should I  : 
-    use a WaitPage for the bots ?
-    recode the WaitPage in Bots ? But how to implement an overall synchronous function over every bot ? 

Second question : is the following way to implement a differing form_fields right for bots ?
The following page, Page1, requires different form form_fields différents according to the Boolean value of this attribute : 
    def get_form_fields(player):
        if player.attribut:
            return [‘complete_variable’]
        else :
            player.complete_variable = False

In tests.py : 
yield WaitPage1
print(f"Attribute in WaitPage1 for the bot : {self.field_maybe_none(‘attribut)}")
form_fields_page1 = AchatEffectif.get_form_fields(self.player)
if ‘complete_variable’ in form_fields_page1:
           yield Page1, dict(complete_variable=random.choice([True, False]))

(But here the formfields depend on a variable implemented in WaitPage1, and which is (inexplicably) considered as None in Page1, but only for Bots).
Any help appreciated ! Thank you very much !

Write a reply

Set forum username