from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class Introduction(Page): def is_displayed(self): return self.round_number == 1 class Decision(Page): form_model = 'player' form_fields = ['decision'] class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): for p in self.group.get_players(): p.set_payoff() class Results(Page): def vars_for_template(self): me = self.player opponent = me.other_player() return { 'my_decision': me.decision, 'opponent_decision': opponent.decision, 'same_choice': me.decision == opponent.decision, 'player_in_all_rounds': self.player.in_all_rounds(), 'total_payoff': sum([p.payoff for p in self.player.in_all_rounds()]), } class End(Page): def is_displayed(self): return self.round_number == 3 def vars_for_template(self): if self.round_number == 3: self.participant.payoff = c(0) return { 'experiment_payoff': self.participant.payoff, } else: pass class StartWait(WaitPage): def is_displayed(self): return self.round_number == 1 wait_for_all_groups = True template_name = 'staghunt_training/StartWait.html' page_sequence = [ StartWait, Introduction, Decision, ResultsWaitPage, Results, End ]