from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'red_or_blue' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 20 STAG = 10 HARE = 5 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,'ウサギ'],[1,'シカ']], 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] 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 page_sequence = [FirstPage, MyPage, ResultsWaitPage, Results,ShuffleWaitPage,Finish]