from otree.api import * author = 'Alistair Munro, Fitawhidan Nashuha, and Gerald Ezra Charles' doc = """ Coin-Flip Gambling Task by Fitawhidan Nashuha (Trial Rounds). """ GAME_PARAMS = [ {"multiplier": 1.2, "prob": 0.2969}, {"multiplier": 1.5, "prob": 0.2714}, {"multiplier": 2.0, "prob": 0.2375}, {"multiplier": 1.3, "prob": 0.2879}, {"multiplier": 1.8, "prob": 0.25}, ] class C(BaseConstants): NAME_IN_URL = 'd_coin_nash_trial' PLAYERS_PER_GROUP = None NUM_ROUNDS = 5 INITIAL_BALANCE = cu(50000) # starting credits class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): if self.round_number == 1: p.participant.vars['balance'] = C.INITIAL_BALANCE p.participant.vars['play_next_round'] = True index = (self.round_number - 1) % len(GAME_PARAMS) params = GAME_PARAMS[index] p.multiplier = params["multiplier"] p.win_probability = params["prob"] class Group(BaseGroup): pass class Player(BasePlayer): final_balance = models.CurrencyField() multiplier = models.FloatField() win_probability = models.FloatField() round_payoff = models.CurrencyField() coin_result = models.StringField() round_win = models.BooleanField() round_payoff = models.CurrencyField() def set_final_balance(player): if player.round_number == C.NUM_ROUNDS: player.final_balance = player.participant.vars.get('balance', 0) def vars_for_template(player): return dict( round_number=player.round_number ) bet_amount = models.CurrencyField( choices=[ (cu(x), f"{x:,}".replace(",", ".")) for x in range(0, 50001, 500) ], label='
How much would you like to bet in this round?
'
'Please choose from the options available in the box below.
Please choose one:
' ) # Next Round? ## Consent play_round = models.BooleanField( choices=[[True, 'Yes, I want to play'], [False, 'No, I want to stop playing']], widget=widgets.RadioSelect, label='Do you want to play in this round?
' ) play_round_sure = models.BooleanField( choices=[[True, 'Yes, I am sure I want to stop playing'], [False, 'No, I want to continue playing']], widget=widgets.RadioSelect, label='Are you sure you want to exit the game?
' ) comprehension_check_1 = models.StringField( label='What will the bonus payment be based on?
', choices=[['1', 'Choices made in only one round'], ['2', 'Choices made only in the practice rounds'], ['3', 'Balance at the end of the game'], ['4', 'Luck in the final round'] ], widget=widgets.RadioSelect, ) comprehension_check_2 = models.StringField( label='Who determines the outcome of each round?
', choices=[['1', 'The participant (me)'], ['2', 'The researchers (manually)'], ['3', 'The game system (game algorithm)'], ['4', 'Other participants'], ], widget=widgets.RadioSelect )