from otree.api import * doc = """ This is the last experiment for my phd dissertation thesis """ class C(BaseConstants): NAME_IN_URL = 'ChapterThree_TheFinal' PLAYERS_PER_GROUP = None NUM_ROUNDS = 20 six_payoff = cu(1) other_payoff = cu(0) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): decision = models.StringField( choices=["one", "two", "three", "four", "five", "six"], doc="Each player's record number is between 1 to 6", widget=widgets.RadioSelect, ) # PAGES class Welcome(Page): def is_displayed(self): return self.round_number == 1 class Introduction(Page): def is_displayed(self): return self.round_number == 1 class Decision(Page): form_model = 'player' form_fields = ['decision'] @staticmethod def before_next_page(player, timeout_happened): import random participant = player.participant # if it's the last round if player.round_number == C.NUM_ROUNDS: random_round = random.randint(1, C.NUM_ROUNDS) participant.selected_round = random_round player_in_selected_round = player.in_round(random_round) if player_in_selected_round.decision == "six": player.payoff = 1 else: player.payoff = 0 class Results(Page): @staticmethod def is_displayed(player: Player): return player.round_number == C.NUM_ROUNDS page_sequence = [Welcome, Introduction, Decision, Results]