from otree.api import * author = 'Alistair Munro, Fitawhidan Nashuha, and Gerald Ezra Charles' doc = """ Coin-Flip Gambling Task by Fitawhidan Nashuha. """ 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' PLAYERS_PER_GROUP = None NUM_ROUNDS = 20 INITIAL_BALANCE = cu(50000) COIN_BALANCE_MAIN = 'coin_main_balance' class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): if self.round_number == 1: p.participant.vars[C.COIN_BALANCE_MAIN] = C.INITIAL_BALANCE p.participant.vars['play_next_round_real'] = 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 def get_language(player): return player.session.config.get('language', 'en') == 'en' # ===================================================== # DYNAMIC LABELS & CHOICES # ===================================================== # ===================================================== # PLAYER # ===================================================== class Player(BasePlayer): # ===================================================== # GAME VARIABLES # ===================================================== final_balance = models.CurrencyField() multiplier = models.FloatField() win_probability = models.FloatField() 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 bet_amount_label(player): if get_language(player): return ( '' 'How much would you like to bet in this round?
' 'Please choose from the options provided below.' '
' ) return ( '' 'Berapa nominal yang hendak Anda pertaruhkan di ronde ini?
' 'Pilih dari pilihan yang tersedia di kotak di bawah ini.' '
' ) def choice_label(player): return ( '

Please choose one:

' if get_language(player) else '

Pilihlah salah satu. Anda dapat mengklik gambar koin:

' ) def choice_choices(player): if get_language(player): return [['H', 'Heads'], ['T', 'Tails']] return [['H', 'Kepala'], ['T', 'Ekor']] def play_round_label(player): return ( '

Do you want to play this round?

' if get_language(player) else '

Apakah Anda ingin bermain di ronde ini?

' ) def play_round_choices(player): if get_language(player): return [ [True, 'Yes, I want to play'], [False, 'No, I want to stop playing'], ] return [ [True, 'Ya, Saya ingin bermain'], [False, 'Tidak, Saya ingin berhenti bermain'], ] def play_round_sure_label(player): return ( '

' 'We would like to confirm your answer again. Please select one option below:' '

' if get_language(player) else '

' 'Apakah Anda yakin untuk keluar dari permainan ini?' '

' ) def play_round_sure_choices(player): if get_language(player): return [ [True, 'I choose not to continue the game'], [False, 'I choose to continue the game'], ] return [ [True, 'Ya, Saya yakin untuk menyudahi permainan'], [False, 'Tidak, Saya ingin melanjutkan permainan'], ] def belief_elicit_1_label(player): if get_language(player): return ( '

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

' ) return ( '

' 'Menurut Anda, bagaimana peluang munculnya Kepala dan Ekor dalam permainan ini?' '

' ) def belief_elicit_1_choices(player): if get_language(player): return [ ['Equal', 'Both have equal probability'], ['Heads', 'Heads appears more often'], ['Tails', 'Tails appears more often'], ['Not Sure', 'I am not sure'], ] return [ ['Equal', 'Keduanya memiliki peluang yang sama'], ['Heads', 'Kepala muncul lebih sering'], ['Tails', 'Ekor muncul lebih sering'], ['Not Sure', 'Saya tidak yakin'], ] def belief_elicit_2_label(player): if get_language(player): return ( '

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

' ) return ( '

' 'Menurut perkiraan Anda, dari 100 ronde, berapa kali koin akan menunjukkan Kepala?' '

' ) # ===================================================== # BETTING # ===================================================== bet_amount = models.CurrencyField( choices=[ (cu(x), f"{x:,}".replace(",", ".")) for x in range(0, 50001, 500) ], label='', ) choice = models.StringField( choices=[ ['H', 'H'], ['T', 'T'], ], widget=widgets.RadioSelect, label='', ) # ===================================================== # CONTINUE / STOP # ===================================================== play_round = models.BooleanField( choices=play_round_choices, widget=widgets.RadioSelect, label='', ) play_round_sure = models.BooleanField( choices=[ [True, 'Exit'], [False, 'Continue'], ], widget=widgets.RadioSelect, ) # ===================================================== # BELIEF ELICITATION # ===================================================== belief_elicit_1 = models.StringField( choices=[ ['Equal', 'Equal'], ['Heads', 'Heads'], ['Tails', 'Tails'], ['Not Sure', 'Not Sure'], ], widget=widgets.RadioSelect, ) belief_elicit_2 = models.IntegerField( choices=list(range(101)) )