from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range 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 = "Пожалуйста, ожидайте другого участника." class Introduction(PageWithBot): """Description of the game: How to play and returns expected""" def is_displayed(self): return self.round_number == 1 class Bid(PageWithBot): """Player: Choose how much to contribute""" form_model = 'player' form_fields = ['bid'] def vars_for_template(self): return dict( item_value=self.player.fx() ) def set_bot_decision(self): self.player.bid = random.randint(0, int(self.player.fx()*100))/100 return self.player.bid class ResultsWaitPage(WaitPage): title_text = "Пожалуйста, подождите" body_text = "Ожидайте пока остальные участники примут решение." def after_all_players_arrive(self): self.group.set_winner() for p in self.group.get_players(): p.set_payoff() p.f_payoff() class Results(PageWithBot): """Players payoff: How much each has earned""" pass class LastRaundWait(WaitPage): title_text = "Пожалуйста, подождите финальных результатов" body_text = "" wait_for_all_groups = True def is_displayed(self): return (self.round_number == Constants.num_rounds) class TotalResult(PageWithBot): def vars_for_template(self): return self.subsession.vars_for_admin_report() def is_displayed(self): return self.round_number == Constants.num_rounds page_sequence = [ StartWaitPage, Introduction, Bid, ResultsWaitPage, Results, LastRaundWait, TotalResult ]