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 = 'e1_coin_nash_trial' PLAYERS_PER_GROUP = None NUM_ROUNDS = 5 INITIAL_BALANCE = cu(50000) 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 def get_language(player): return player.session.config.get('language', 'en') == 'en' 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() def set_final_balance(player): if player.round_number == C.NUM_ROUNDS: player.final_balance = player.participant.vars.get('balance', 0) # ===================================================== # BET AMOUNT # ===================================================== bet_amount = models.CurrencyField( choices=[ (cu(x), f"{x:,}".replace(",", ".")) for x in range(0, 50001, 500) ], label='', ) # ===================================================== # HEADS / TAILS CHOICE # ===================================================== @staticmethod def choice_choices(player): if get_language(player): return [ ['H', 'Heads'], ['T', 'Tails'], ] return [ ['H', 'Kepala'], ['T', 'Ekor'], ] @staticmethod def choice_label(player): if get_language(player): return ( '

' 'Please choose one (you may click on the coin image):' '

' ) return ( '

' 'Pilihlah salah satu (Anda boleh meng-klik gambar koin):' '

' ) choice = models.StringField( choices=choice_choices, widget=widgets.RadioSelect, label=choice_label, ) # ===================================================== # PLAY ROUND # ===================================================== @staticmethod 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'], ] @staticmethod def play_round_label(player): if get_language(player): return ( '

' 'Do you want to play this round?' '

' ) return ( '

' 'Apakah Anda ingin bermain di ronde ini?' '

' ) play_round = models.BooleanField( choices=play_round_choices, widget=widgets.RadioSelect, label=play_round_label, ) # ===================================================== # CONFIRM STOPPING # ===================================================== @staticmethod 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'], ] @staticmethod def play_round_sure_label(player): if get_language(player): return ( '

' 'We would like to confirm your answer again. ' 'Please select one of the following options:' '

' ) return ( '

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

' ) play_round_sure = models.BooleanField( choices=play_round_sure_choices, widget=widgets.RadioSelect, label=play_round_sure_label, ) # ===================================================== # COMPREHENSION CHECK 1 # ===================================================== @staticmethod def comprehension_check_1_choices(player): if get_language(player): return [ ['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'], ] return [ ['1', 'Pilihan dibuat hanya dalam suatu ronde'], ['2', 'Pilihan dibuat hanya dalam ronde latihan'], ['3', 'Saldo di akhir permainan'], ['4', 'Keberuntungan di ronde terakhir'], ] comprehension_check_1 = models.StringField( choices=comprehension_check_1_choices, widget=widgets.RadioSelect, label='', ) # ===================================================== # COMPREHENSION CHECK 2 # ===================================================== # @staticmethod # def comprehension_check_2_label(player): # return ( # '

' # 'Who determines the outcome of each round?' # '

' # if get_language(player) # else # '

' # 'Siapa yang menentukan hasil setiap putaran?' # '

' # ) @staticmethod def comprehension_check_2_choices(player): if get_language(player): return [ ['1', 'Participant (me)'], ['2', 'Researchers (manually)'], ['3', 'The game system (algorithm)'], ['4', 'Other participants'], ] return [ ['1', 'Partisipan (Saya)'], ['2', 'Para peneliti (secara manual)'], ['3', 'Sistem permainan (algoritma permainan)'], ['4', 'Partisipan lain'], ] comprehension_check_2 = models.StringField( choices=comprehension_check_2_choices, widget=widgets.RadioSelect, label='', )