from otree.api import * author = 'Alistair Munro, Fitawhidan Nashuha, and Gerald Ezra Charles' doc = """ Coin-Flip Gambling Task by Fitawhidan Nashuha. """ # models.py (main game) GAME_PARAMS = [ {"multiplier": 1.2, "prob": 0.2969}, # House Edge = 5% {"multiplier": 1.5, "prob": 0.2714}, # House Edge = 5% {"multiplier": 2.0, "prob": 0.2375}, # House Edge = 5% {"multiplier": 1.3, "prob": 0.2879}, # House Edge = 5% {"multiplier": 1.8, "prob": 0.25}, # House Edge = 5% ] class C(BaseConstants): NAME_IN_URL = 'd_coin_nash' PLAYERS_PER_GROUP = None NUM_ROUNDS = 20 INITIAL_BALANCE = cu(50000) # starting credits COIN_BALANCE_MAIN = 'coin_main_balance' class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): # Initialize balance in the first round if self.round_number == 1: p.participant.vars[C.COIN_BALANCE_MAIN] = C.INITIAL_BALANCE p.participant.vars['play_next_round_real'] = True # Determine which set of parameters to use for this round index = (self.round_number - 1) % len(GAME_PARAMS) params = GAME_PARAMS[index] # Assign to player 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() # outcome variables 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(C.COIN_BALANCE_MAIN, 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.

' ) choice = models.StringField( choices=[['H', 'Heads'], ['T', 'Tails']], widget=widgets.RadioSelect, label='

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?

' ) belief_elicit_1 = models.StringField( label='

In your opinion, what are the chances of Heads and Tails appearing in this game?

', choices=[ ['Equal', 'They have equal chances'], ['Heads', 'Heads appears more often'], ['Tails', 'Tails appears more often'], ['Not Sure', 'I am not sure'] ], widget=widgets.RadioSelect, ) belief_elicit_2 = models.IntegerField( label='

In your estimation, out of 100 rounds, how many times will the coin land on Heads?

', choices=list(range(101)) )