oTree Forum >

Testing live methods in single player games

#1 by Christoph

Hi everybody,
I am currently testing a single player experiment which includes a live method. I wanted to run some automated tests and generate some test data to see if everything works as intended (as data from one treatment will be used as information in another treatment). Additionally, I also use an ExtraModel. Running the bots from the command line with --export doesn't seem to also export the ExtraModel.

However, I ran into a problem trying to write the bots. Specifically, method() requires to include the id in group as an argument (https://otree.readthedocs.io/en/latest/misc/bots_advanced.html#live-pages). Trying to get player.id_in_group in different variations did not work for me, but I am not entirely sure how call_live_method() really works. 

This of course leads to problems, as calls such as method(1: something) will correctly played by the first bot, but not by the subsequent ones (which have another id as group size is None). Providing multiple calls such as method(1: something), method(2: something), etc. similarly encounters the problem that method(1: something) doesn't work for player 2. I tried to work around this by using try/except but still ran into errors.

Is there a way to flexibly target individual players in single players experiment when testing live methods?

Anyway, I found a rather dirty fix to still run multiple bots though my live pages and get sample data from my ExtraModel:

1. Include method(1: something) in tests.py
2. Set C.PLAYERS_PER_GROUP = None
3. Start the server
4. Change C.PLAYERS_PER_GROUP = 1 and save (if you do this before starting the server, otree will complain that group size should be None and the server won't start).
5. Now every player will be part of their own group with id = 1
6. Open the indivdual links, the bots should correctly play through the experiment
7. Get the ExtraModel from the data tab

#2 by dgellscm (edited )

Unfortunately, I cannot answer your question. I would like to add my problem which seems like it has a similar domain:

A player competes in an auction against a bot, using livepages. It generally works as intended, except when there are players of the same group accidentally on the exact same page. Then the input of one player is also registered for the second player. Again, this would not be the case if player 1 did their input first, would then go to the next page, and player 2 enters the page thereafter. It is only an issue when they are on the same page of the app at the same time (which is something I do not want to avoid).

Maybe a solution to your problem would also help me, because your dirty fix is also what I found to be successful. Unfortunately, I don't think this possible when conducting a real experiment.

Edit: Typos

#3 by Michael (edited )

Hello everyone,
Is there already a solution to the problem above? I would also like to implement bots with live pages in a single player game.

Write a reply

Set forum username