from otree.api import * c = cu doc = '' class Constants(BaseConstants): name_in_url = 'two_round_gambling' players_per_group = None num_rounds = 2 AApayoff = cu(10) ABpayoff = cu(-2) BApayoff = cu(4) BBpayoff = cu(4) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass def set_payoff(player): import random chance = random.randint(1,100) if chance <= 50: player.botchoice = "A" elif chance > 50: player.botchoice = "B" if player.botchoice == "A" and player.decision == "A": player.payoff = Constants.AApayoff elif player.botchoice == "B" and player.decision == "A": player.payoff = Constants.ABpayoff elif player.botchoice == "B" and player.decision == "B" or player.botchoice == "A" and player.decision == "B": player.payoff = Constants.BBpayoff class Player(BasePlayer): decision = models.StringField(choices=[['A', 'A'], ['B', 'B']]) botchoice = models.StringField(choices=[['A', 'A'], ['B', 'B']]) prolific_id = models.StringField(label='Please enter your Prolific ID') class Consent(Page): form_model = 'player' form_fields = ['prolific_id'] @staticmethod def is_displayed(player): return player.round_number == 1 class Instructions(Page): form_model = 'player' @staticmethod def is_displayed(player): return player.round_number == 1 class Decision(Page): form_model = 'player' form_fields = ['decision'] @staticmethod def before_next_page(player, timeout_happened): import random chance = random.randint(1,100) if chance <= 50: player.botchoice = "A" elif chance > 50: player.botchoice = "B" if player.botchoice == "A" and player.decision == "A": player.payoff = Constants.AApayoff elif player.botchoice == "B" and player.decision == "A": player.payoff = Constants.ABpayoff elif player.botchoice == "B" and player.decision == "B" or player.botchoice == "A" and player.decision == "B": player.payoff = Constants.BBpayoff class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player): return dict(botchoice = player.botchoice) @staticmethod def before_next_page(player, timeout_happened): if player.round_number == 1: player.payoff = player.payoff + 10 class Debrief(Page): form_model = 'player' @staticmethod def is_displayed(player): return player.round_number == 2 page_sequence = [Consent, Instructions, Decision, Results, Debrief]