from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'centipede' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 3 payoff_choices=[(4,2), (3,6), (8,4), (5,10), (12,6), (7,14), (16,8),] choices = ['Pass','Take'] def creating_session(self): self.group_randomly() for p in self.get_players(): p.get_role_of_player() class Subsession(BaseSubsession): pass class Group(BaseGroup): Continue = models.StringField(choices=C.choices, initial='Pass', widget=widgets.RadioSelect(), doc="Direction Choice") page_num = models.IntegerField(initial=1) def count_pages(group): group.page_num += 1 class Player(BasePlayer): role_of_player = models.StringField(doc="""Role in group""") student_ID = models.IntegerField(label="Please enter your student ID to proceed") payment = models.IntegerField() def get_role_of_player(player): if player.id_in_group == 1: player.role_of_player = 'Person A' elif player.id_in_group == 2: player.role_of_player = 'Person B' def set_payoffs(self): for p in self.get_players(): p.payment = C.payoff_choices[self.page_num-1][(p.id_in_group-1)] # PAGES class ID_Entry(Page): form_model = 'player' form_fields = ['student_ID'] @staticmethod def is_displayed(subsession): return subsession.round_number == 1 class PersonA(Page): form_model = 'group' form_fields = ['Continue'] @staticmethod def is_displayed(player): group = player.group return player.role_of_player == 'Person A' and group.Continue == 'Pass' @staticmethod def before_next_page(player, timeout_happened): group = player.group if group.Continue == 'Pass': group.count_pages() class PersonB(Page): form_model = 'group' form_fields = ['Continue'] @staticmethod def is_displayed(player): group = player.group return player.role_of_player == 'Person B' and group.Continue == 'Pass' @staticmethod def before_next_page(player, timeout_happened): group = player.group if group.Continue == 'Pass': group.count_pages() class IntWaitPage(WaitPage): @staticmethod def is_displayed(player): group = player.group return group.Continue == 'Pass' class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' class Results(Page): pass class ShuffleWaitPage(WaitPage): wait_for_all_groups = True page_sequence = [ID_Entry, PersonA, IntWaitPage, PersonB, IntWaitPage, PersonA, IntWaitPage, PersonB, IntWaitPage, PersonA, IntWaitPage, PersonB, ResultsWaitPage, Results, ShuffleWaitPage ]