from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'stag_hunt_game' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 STAG = 100000 HARE = 50000 MISMATCH = 0 class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_payoffs(self): h_1 = self.get_player_by_role('Hunter_1') h_2 = self.get_player_by_role('Hunter_2') if h_1.flag == 1 and h_2.flag == 1: h_1.payoff = C.STAG h_2.payoff = C.STAG elif h_1.flag == 0 and h_2.flag == 0: h_1.payoff = C.HARE h_2.payoff = C.HARE else: h_1.payoff = C.MISMATCH h_2.payoff = C.MISMATCH class Player(BasePlayer): flag = models.BooleanField(label='どちらに投資するかお答えください', choices=[[0,'B社'],[1,'A社']], widget=widgets.RadioSelect) def role(self): if self.id_in_group == 1: return 'Hunter_1' if self.id_in_group == 2: return 'Hunter_2' def other_player(self): return self.get_others_in_group()[0] age = models.IntegerField(label='あなたの年齢をお書きください') gender = models.IntegerField(label='あなたの性別を選択してください', choices = [[1,'男'],[2,'女'],[1,'その他'],], widget= widgets.RadioSelect) faculty = models.IntegerField(label='あなたの学部を選択してください', choices = [[1,'文学部'],[2,'教育学部'],[3,'心理学部'],[4,'現代ビジネス学部'],[5,'家政学部'],[6,'薬学部'],[7,'看護学部']], widget = widgets.RadioSelect ) riskA = models.IntegerField( label='問1', choices=[[0,'1/10で300円か9/10で250円'],[1,'1/10で500円か9/10で50円']], widget=widgets.RadioSelect ) riskB = models.IntegerField( label='問2', choices=[[0,'2/10で300円か8/10で250円'],[1,'2/10で500円か8/10で50円']], widget=widgets.RadioSelect ) riskC = models.IntegerField( label='問3', choices=[[0,'3/10で300円か7/10で250円'],[1,'3/10で500円か7/10で50円']], widget=widgets.RadioSelect ) riskD = models.IntegerField( label='問4', choices=[[0,'4/10で300円か6/10で250円'],[1,'4/10で500円か7/10で50円']], widget=widgets.RadioSelect ) riskE = models.IntegerField( label='問5', choices=[[0,'5/10で300円か5/10で250円'],[1,'5/10で500円か5/10で50円']], widget=widgets.RadioSelect ) riskF = models.IntegerField( label='問6', choices=[[0,'6/10で300円か4/10で250円'],[1,'6/10で500円か4/10で50円']], widget=widgets.RadioSelect ) riskG = models.IntegerField( label='問7', choices=[[0,'7/10で300円か3/10で250円'],[1,'7/10で500円か3/10で50円']], widget=widgets.RadioSelect ) riskH = models.IntegerField( label='問8', choices=[[0,'8/10で300円か2/10で250円'],[1,'8/10で500円か2/10で50円']], widget=widgets.RadioSelect ) riskI = models.IntegerField( label='問9', choices=[[0,'9/10で300円か1/10で250円'],[1,'9/10で500円か1/10で50円']], widget=widgets.RadioSelect ) riskJ = models.IntegerField( label='問10', choices=[[0,'10/10で300円か0/10で250円'],[1,'10/10で500円か0/10で50円']], widget=widgets.RadioSelect ) emotion01_1 = models.BooleanField(blank=True) emotion02_1 = models.BooleanField(blank=True) emotion03_1 = models.BooleanField(blank=True) emotion04_1 = models.BooleanField(blank=True) emotion05_1 = models.BooleanField(blank=True) emotion06_1 = models.BooleanField(blank=True) emotion07_1 = models.BooleanField(blank=True) emotion08_1 = models.BooleanField(blank=True) emotion09_1 = models.BooleanField(blank=True) emotion10_1 = models.BooleanField(blank=True) emotion01_2 = models.BooleanField(blank=True) emotion02_2 = models.BooleanField(blank=True) emotion03_2 = models.BooleanField(blank=True) description = models.StringField() def creating_session(subsession): subsession.group_randomly() # PAGES class FirstPage(Page): @staticmethod def is_displayed(player): return player.round_number == 1 class MyPage(Page): form_model='player' form_fields=['flag'] class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() class Results(Page): def vars_for_template(player): opponent = player.other_player() return dict( my_flag=player.flag, opponent_flag=opponent.flag, ) class ShuffleWaitPage(WaitPage): wait_for_all_groups = True class Finish(Page): @staticmethod def is_displayed(player): return player.round_number == C.NUM_ROUNDS class SecondPage(Page): pass class Risk(Page): form_model='player' form_fields=['riskA','riskB','riskC','riskD','riskE','riskF','riskG','riskH','riskI','riskJ'] class emotion_1(Page): form_model='player' form_fields=['emotion01_1','emotion02_1','emotion03_1','emotion04_1','emotion05_1', 'emotion06_1','emotion07_1','emotion08_1','emotion09_1','emotion10_1','description'] class emotion_2(Page): form_model='player' form_fields=['emotion01_2','emotion02_2','emotion03_2'] class Zokusei(Page): form_model='player' form_fields=['age','gender','faculty'] page_sequence = [Zokusei,emotion_1, Risk, FirstPage, SecondPage, MyPage, ResultsWaitPage, Results,ShuffleWaitPage,Finish] ##