from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random class PageWithBot(Page): is_first_round_show = False is_last_round_show = False def is_enabled(self): if self.is_first_round_show: return (self.round_number == 1) if self.is_last_round_show: return (self.round_number == Constants.num_rounds) return True def set_bot_decision(self): pass def is_displayed(self): if not self.is_enabled(): return False if not self.player.is_alive(): # this is bot self.set_bot_decision() return False return True class StartWaitPage(WaitPage): wait_for_all_groups = True title_text = "Пожалуйста, подождите" body_text = "Пожалуйста, ожидайте другого участника." # def after_all_players_arrive(self): # self.subsession.do_my_shuffle() class Introduction(PageWithBot): is_first_round_show = True # def is_enabled(self): # return (self.round_number == 1) class Decision1(PageWithBot): """This page is only for P1 P1 sends amount (all, some, or none) to P2 This amount is tripled by experimenter, i.e if sent amount by P1 is 5, amount received by P2 is 15""" form_model = 'group' form_fields = ['decision1'] def is_enabled(self): return (self.player.id_in_group == 1) def vars_for_template(self): return dict( nature=self.group.fnature() ) def set_bot_decision(self): self.group.decision1 = 'Предъявлять' return self.group.decision1 class SendBackWaitPage(WaitPage): title_text = "Пожалуйста, подождите" body_text = "Ожидайте пока Ваш оппонент примет решение." class Decision2(PageWithBot): """This page is only for P2 P2 sends back some amount (of the tripled amount received) to P1""" form_model = 'group' form_fields = ['compensation'] def is_enabled(self): return (self.player.id_in_group == 2) def vars_for_template(self): return dict( nature=self.group.fnature() ) def set_bot_decision(self): if self.group.decision1 == 'Предъявлять': self.group.decision2 = self.group.fnature() else: self.group.decision2 = 50 return self.group.decision2 class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() title_text = "Пожалуйста, подождите" body_text = "Ожидайте пока Ваш оппонент примет решение." class Results(PageWithBot): """This page displays the earnings of each player""" def vars_for_template(self): return dict( other_player_payoff=self.player.other_player().payoff, nature=self.group.fnature(), compensation=self.group.compensation ) class LastRaundWait(WaitPage): title_text = "Пожалуйста, подождите финальных результатов" body_text = "" wait_for_all_groups = True def is_displayed(self): return (self.round_number == Constants.num_rounds) class WaitFinished(PageWithBot): def is_enabled(self): return (self.round_number == Constants.num_rounds) def vars_for_template(self): return self.subsession.vars_for_admin_report() page_sequence = [ StartWaitPage, Introduction, Decision1, SendBackWaitPage, Decision2, ResultsWaitPage, Results, LastRaundWait, WaitFinished ]