from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'puzzle' PLAYERS_PER_GROUP = None NUM_ROUNDS = 20 pay_amount = [3.00, 2.80, 2.60, 2.40, 2.20, 2.00, 1.80, 1.60, 1.40, 1.20, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00] PASSWORD = 'pass' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): moveon = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label='Do you want to continue to the next round?') round_pay = models.CurrencyField(label='Payment Earned if Round is Completed') password = models.IntegerField() has_password = models.BooleanField(initial=False) completion_time = models.IntegerField(initial=0) time_intervals = models.StringField() # temp_return=models.BooleanField(inital=False) def creating_session(subsession): for p in subsession.get_players(): p.round_pay = C.pay_amount[p.round_number - 1] p.participant.payoff = 0 class Round_start(Page): form_model = 'player' form_fields = ['moveon'] class Build(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.moveon == True @staticmethod def live_method(player: Player, data): if ('password' in data): if data['password'] == 9999: #abort round for participants who wish to quit without completing round player.moveon = False elif data['password'] == 1000: player.moveon = True player.participant.payoff += player.round_pay else: return {0: dict(error="Incorrect password")} player.password = data['password'] player.has_password = True player.completion_time = data['completion_time'] player.time_intervals = data['time_intervals'] # broadcast to the whole group whether the game is finished return {0: dict(finished=player.has_password)} @staticmethod def error_message(player: Player, values): if not player.has_password: return "Experimenter has not input data yet" class Round_quit(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.moveon == False def app_after_this_page(player: Player, upcoming_apps): return upcoming_apps[0] # def is_temp_return(player: Player): # if player.temp_return == True: # return page_sequence = [Round_start, Build, Round_quit]