from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'WakeKoba_hunt_proj_ver_2' PLAYERS_PER_GROUP = 3 NUM_ROUNDS = 10 SIGMA = 5 class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_payoffs(self): import random for p in self.get_players(): if self.round_number > 1: if p.observe != 0: p.arrow_height = p.in_round(self.round_number - 1).arrow_height p.arrow_width = p.in_round(self.round_number - 1).arrow_width p.count_inno = p.in_round(self.round_number - 1).count_inno if p.observe == 2: p.count_inno += 1 if p.dimension == 1: p.arrow_height += 10 elif p.dimension ==2: p.arrow_width += -10 total_curr = 200 + (p.count_inno*20) p.total_inno = int(round(random.gauss(total_curr, C.SIGMA))) def copy_agent(self): for p in self.get_players(): if p.copy1 == 1: p.arrow_height = self.in_round(p.round_number).get_player_by_id(1).arrow_height p.arrow_width = self.in_round(p.round_number).get_player_by_id(1).arrow_width p.count_inno = self.in_round(p.round_number).get_player_by_id(1).count_inno elif p.copy1 == 2: p.arrow_height = self.in_round(p.round_number).get_player_by_id(2).arrow_height p.arrow_width = self.in_round(p.round_number).get_player_by_id(2).arrow_width p.count_inno = self.in_round(p.round_number).get_player_by_id(2).count_inno elif p.copy1 == 3: p.arrow_height = self.in_round(p.round_number).get_player_by_id(3).arrow_height p.arrow_width = self.in_round(p.round_number).get_player_by_id(3).arrow_width p.count_inno = self.in_round(p.round_number).get_player_by_id(3).count_inno class Player(BasePlayer): dimension = models.IntegerField(choices=[[0,'none'],[1,'height'],[2,'width']], widget=widgets.RadioSelect, initial=0) observe = models.IntegerField(label="改良、狩り", widget=widgets.RadioSelect, choices=[[1,'Hunt'],[2,'Modify']], initial=0) copy_or_pass = models.IntegerField(label="模倣するか選択してください", widget=widgets.RadioSelect, choices=[[1,'Copy'],[2,'Pass']], initial=0) total_inno = models.IntegerField() count_inno = models.IntegerField(initial=0) copy1 = models.IntegerField(label = '誰を真似ますか?', choices=[[0,'選ばれず'],[1,'プレイヤー1'],[2,'プレイヤー2'],[3,'プレイヤー3']], initial=0) arrow_height = models.IntegerField(initial=50) arrow_width = models.IntegerField(initial=200) def role(self): if self.id_in_group==1: return 'Wake' elif self.id_in_group==2: return 'Koba' elif self.id_in_group==3: return 'Toyo' else: return 'pass' # # PAGES class Obs_or_Pass(Page): form_model = 'player' form_fields = ['observe'] class Observe(Page): @staticmethod def is_displayed(player): return player.copy_or_pass == 1 form_model = 'player' form_fields = ['copy1'] class Modify(Page): @staticmethod def is_displayed(player): return player.observe == 2 form_model = 'player' form_fields= ['dimension'] def js_vars(player): if player.round_number > 1: cumuheight = player.in_round(player.round_number - 1).arrow_height cumuwidth = player.in_round(player.round_number - 1).arrow_width else: cumuheight = player.arrow_height cumuwidth = player.arrow_width return dict( cheight=cumuheight, cwidth=cumuwidth, ) class ResultsWaitPage(WaitPage): template_name = 'WakeKoba_hunt_proj/MyWaitPage.html' def after_all_players_arrive(self): self.group.set_payoffs() class Result(Page): pass class WaitResults(WaitPage): pass class Result2(Page): form_model = 'player' form_fields = ['copy_or_pass'] class Wait_Next_day(WaitPage): def after_all_players_arrive(self): self.group.copy_agent() class Test(Page): pass page_sequence = [Obs_or_Pass, Modify, ResultsWaitPage, Result, WaitResults, Result2, Observe, Wait_Next_day]