I am facing a problem: my last page is coded in a way such that when the game reaches the final round, it will automatically pick a random round and will show payoff from that randomly selected round. When I am manually trying the session, it works fine and showing the desired last page. But
when I am using bot, it is failing to show the last page give=ing an error like: AssertionError: Bot expects to be on page Payoff but current page is /p/hzt9jyop/grp_contst_bot/MyPage/9. Check your bot code, then create a new session.
my last page code is like the followings:
python code
class Payoff(Page):
@staticmethod
def is_displayed(player: Player):
return player.round_number == C.NUM_ROUNDS
html page code
{{ block content }}
{{ if subsession.round_number == C.NUM_ROUNDS }}
<p>
Round {{ participant.selected_round }} was randomly selected for payment.
Your final payoff is therefore {{ player.payoff_final }}.
</p>
{{ endif }}
and my bot code is like following:(tests.py)
from otree.api import Currency as c, currency_range
from . import *
from otree.api import Bot, SubmissionMustFail
import random
class PlayerBot(Bot):
def play_round(self):
if self.subsession.round_number == 1:
yield Welcome
# yield SubmissionMustFail(MyPage, {"contribution": random.choice(currency_range(0, C.ENDOWMENT,1))})
# yield MyPage, {"contribution": random.choice(currency_range(0, C.ENDOWMENT,1))}
#yield SubmissionMustFail(MyPage, {"contribution": random.randint(0, C.ENDOWMENT+1)})
yield MyPage, {"contribution": random.randint(0, C.ENDOWMENT)}
yield Results
yield Payoff
{{ endblock }}
Can you say what is going wrong in my tests.py code??