from otree.api import * doc = """ Random number of rounds for multiplayer (random stopping rule) """ class Constants(BaseConstants): name_in_url = 'random_num_rounds_multiplayer' players_per_group = None # choose num_rounds high enough that the chance of # maxing out is negligible num_rounds = 50 stopping_probability = 0.2 class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): for p in subsession.get_players(): p.participant.finished_rounds = False class Group(BaseGroup): pass class Player(BasePlayer): pass # PAGES class MyPage(Page): pass class ResultsWaitPage(WaitPage): @staticmethod def after_all_players_arrive(group: Group): import random if random.random() < Constants.stopping_probability: print('ending game') for p in group.get_players(): p.participant.finished_rounds = True # your usual after_all_players_arrive goes here... class Results(Page): @staticmethod def app_after_this_page(player: Player, upcoming_apps): participant = player.participant if participant.finished_rounds: return upcoming_apps[0] page_sequence = [MyPage, ResultsWaitPage, Results]