from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants 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 Decision_seller(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 = ['seller_price'] def vars_for_template(self): return dict( x=self.player.fx() ) def set_bot_decision(self): self.group.seller_price = max(0.67*self.player.fx()+25, 35) def is_enabled(self): return (self.player.id_in_group == 1) class Decision_buyer(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 = ['buyer_price'] def vars_for_template(self): return dict( x=self.player.fx() ) def set_bot_decision(self): self.group.buyer_price = max(0.67*self.player.fx()+25/3, 65) def is_enabled(self): return (self.player.id_in_group == 2) 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( x=self.player.x, o_x = self.player.other_player().x, payoff = self.player.f_payoffs(), o_payoff = self.player.other_player().f_payoffs() ) 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, Decision_seller, Decision_buyer, ResultsWaitPage, Results, LastRaundWait, WaitFinished ]