from otree.api import * doc = """ Cheating Paradigm game """ author = "Tim Bonowski" class C(BaseConstants): #CORE CONSTANTS NAME_IN_URL = 'coin_flip' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 TREATMENTS = ['Phone', 'Zoom', 'Email', 'Mailbox', 'Click'] PASSWORD_WIN = 'zahlzahl' PASSWORD_LOSE = 'fragebogen' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): communication_mode = models.StringField() password = models.StringField() def creating_session(subsession): session = subsession.session print(C.TREATMENTS[session.config['media_treatment']]) media_treatment = session.config['media_treatment'] if subsession.round_number == 1: communication_mode = C.TREATMENTS[media_treatment] for player in subsession.get_players(): participant = player.participant #fixed treatment on participant and not player so that it would not change between rounds participant.communication_mode = communication_mode #need to add this field in setting.py # FUNCTIONS def set_payoffs(player): print(player.password) if player.password == 'zahlzahl': player.payoff = cu(9) print(player.payoff) else: player.payoff = cu(5) # PAGES class Einfuehrung(Page): @staticmethod def is_displayed(player): return player.round_number == 1 def vars_for_template(player): participant = player.participant return dict( participant_communication_mode=participant.communication_mode, ) class FlipCoinInstructions(Page): pass class FlipCoin(Page): pass class CommunicationMode(Page): form_model = 'player' form_fields = ['password'] @staticmethod def vars_for_template(player): participant = player.participant return dict( participant_communication_mode=participant.communication_mode, ) @staticmethod def error_message(player, values): if values['password'] != C.PASSWORD_WIN and values['password'] != C.PASSWORD_LOSE: return f'Wrong password!' # class ResultsWaitPage(WaitPage): # wait_for_all_groups = False # after_all_players_arrive = set_payoffs class Results(Page): @staticmethod def before_next_page(player, timeout_happened): set_payoffs(player) page_sequence = [Einfuehrung, FlipCoinInstructions, FlipCoin, CommunicationMode, # ResultsWaitPage, Results]