from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import numpy as np import random def vars_for_all_templates(self): return { 'M1': self.player.participant.vars['list_M3'][self.round_number-1][0], 'M2': self.player.participant.vars['list_M3'][self.round_number-1][1], 'M3': self.player.participant.vars['list_M3'][self.round_number-1][2], 'round_number' : 4*(self.round_number-1) +1, 'round_number_1': 4*(self.round_number-1) +2, 'round_number_2': 4*(self.round_number-1) +3, 'round_number_3': 4*(self.round_number-1) +4, 'result_part2_random': self.player.participant.vars['result_part2_random'], 'result_part2_payoff': self.player.participant.vars['result_part2_payoff'], 'result_part2_cards': self.player.participant.vars['result_part2_cards'], } class Instruction(Page): def is_displayed(self): return self.round_number == 1 class Risk(Page): form_model = 'player' form_fields = ['Certainty'] class Risk_2(Page): form_model = 'player' form_fields = ['Certainty_2'] def before_next_page(self): if self.player.round_number == 2: if self.player.participant.vars['result_part2_random'] >= self.player.Certainty_2: self.player.participant.vars['result_part2_cards'] = [self.player.participant.vars['list_M3'][self.round_number-1][0], self.player.participant.vars['list_M3'][self.round_number-1][2]] self.player.participant.vars['result_part2_payoff'] = (self.player.participant.vars['result_part2_random'] - 1) * 5 self.player.participant.vars['result_part2_option1option2']=0 else: self.player.participant.vars['result_part2_cards'] = [self.player.participant.vars['list_M3'][self.round_number-1][0], self.player.participant.vars['list_M3'][self.round_number-1][2]] self.player.participant.vars['result_part2_payoff'] = random.choice(self.player.participant.vars['result_part2_cards']) self.player.participant.vars['result_part2_option1option2']=1 class Risk_3(Page): form_model = 'player' form_fields = ['Certainty_3'] class Risk_4(Page): form_model = 'player' form_fields = ['Certainty_4'] class Next_part(Page): def is_displayed(self): return self.round_number == Constants.num_rounds class Next_choice(Page): pass class Next_choice_2(Page): pass class Next_choice_3(Page): pass class Next_choice_4(Page): def is_displayed(self): return self.round_number < Constants.num_rounds page_sequence = [Risk, Next_choice, Risk_2,Next_choice_2,Risk_3,Next_choice_3, Risk_4,Next_choice_4, Next_part]