from otree.api import * import time class C(BaseConstants): NAME_IN_URL = 'WTP_info' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 N_size = 4 Prize = 3 Bet_Limit = 1.5 SELF_ROLE = 'self_strategy' OTHER_ROLE = 'other_strategy' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): wtp_self = models.FloatField( label=''' How much are you willing to pay (your bet) to observe the sample of 4 marbles and apply YOUR strategy?''', choices=[x / 100 for x in range(0, int(C.Bet_Limit*100 + 1), 10)], ) self_bet = models.FloatField() # result from decision of other wtp_other = models.FloatField( label=''' How much are you willing to pay (your bet) to observe a sample of 4 marbles and apply PARTICIPANTS 2's strategy?''', choices=[x / 100 for x in range(0, int(C.Bet_Limit*100 + 1), 5)], ) other_bet = models.FloatField() # times time_instructions = models.IntegerField() time_wtp = models.IntegerField() # FUNCTIONS # PAGES class Section2(Page): @staticmethod def before_next_page(player: Player, timeout_happened): player.time_instructions = int(time.time()) # in this section, a test for understanding is needed class WTP_self(Page): form_model = 'player' form_fields = ['wtp_self'] @staticmethod def before_next_page(player: Player, timeout_happened): import random # random bet x = random.randrange(0, int(C.Bet_Limit*100 +1), 1)/100 # Payoff in dollars # BDM mechanism # Self if player.wtp_self >= x: player.self_bet = player.participant.correct_guess_50 * C.Prize - x else: player.self_bet = random.choice([0, C.Prize]) # final payment player.payoff = player.self_bet player.time_wtp = int(time.time()) @staticmethod def is_displayed(player): return player.role == C.SELF_ROLE class WTP_other(Page): form_model = 'player' form_fields = ['wtp_other'] @staticmethod def before_next_page(player: Player, timeout_happened): import random # random bet x = random.randrange(0, int(C.Bet_Limit*100 +1), 1)/100 # Payoff in dollars # BDM mechanism # Others if player.wtp_other >= x: other = player.get_others_in_group()[0] player.other_bet = other.participant.correct_guess_50 * C.Prize - x else: player.other_bet = random.choice([0, C.Prize]) # final payment player.payoff = player.other_bet player.time_wtp = int(time.time()) @staticmethod def is_displayed(player): return player.role == C.OTHER_ROLE page_sequence = [ Section2, WTP_self, WTP_other, ]