from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'repeated_flip' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 PAYOUT_MATRIX = [[(32, 32), (12, 50)], [(50, 12), (25, 25)]] class Subsession(BaseSubsession): pass class Group(BaseGroup): p1_choice = models.IntegerField() p2_choice = models.IntegerField() round_num = models.IntegerField(initial=0) class Player(BasePlayer): total_payout = models.CurrencyField(initial=0) round_payout = models.CurrencyField(initial=0) choice = models.IntegerField(initial=0) # PAGES class Instructions(Page): pass class InteractionWaitPage(WaitPage): pass class Interaction(Page): @staticmethod def live_method(player, data): player.choice = data['choice'] if player.id_in_group == 1: player.group.p1_choice = data['choice'] - 1 elif player.id_in_group == 2: player.group.p2_choice = data['choice'] - 1 class ResultsWaitPage(WaitPage): @staticmethod def after_all_players_arrive(group: Group): group.round_num += 1 payout_tuple = C.PAYOUT_MATRIX[group.p1_choice][group.p2_choice] group.get_player_by_id(1).round_payout = payout_tuple[0] group.get_player_by_id(1).total_payout += payout_tuple[0] group.get_player_by_id(2).round_payout = payout_tuple[1] group.get_player_by_id(2).total_payout += payout_tuple[1] class AfterInteraction(Page): pass class Results(Page): pass def create_page_sequence(): ps = [] ps.append(Instructions) ps.append(InteractionWaitPage) ps.append(Interaction) ps.append(ResultsWaitPage) ps.append(AfterInteraction) i = random.randint(1, 100) while i <= 50: ps.append(InteractionWaitPage) ps.append(Interaction) ps.append(ResultsWaitPage) ps.append(AfterInteraction) i = random.randint(1, 100) ps.append(Results) return ps page_sequence = create_page_sequence()