from otree.api import Currency as c, currency_range from . import models from ._builtin import Page, WaitPage from .models import Constants, Player class Instructions(Page): def is_displayed(self): return self.round_number == 1 def before_next_page(self): self.session.vars['draw_count'] = 20 self.session.vars['practice_draw_count'] = 5 class Questionnaire(Page): def is_displayed(self): return self.round_number == 1 class FirstCardDrawingPractice(Page): def is_displayed(self): return self.session.vars['practice_draw_count'] >= 2 form_model = Player form_fields = ['first_draw_accepted'] # def vars_for_template(self): # self.player.highest_hands() def before_next_page(self): self.session.vars['practice_draw_count'] = self.session.vars['practice_draw_count'] - 1 class SecondCardDrawingPractice(Page): def is_displayed(self): return self.player.first_draw_accepted and self.session.vars['practice_draw_count'] >= 1 or \ (not self.player.first_draw_accepted and self.session.vars['practice_draw_count'] == 1) def before_next_page(self): # self.player.highest_hands() self.session.vars['practice_draw_count'] = self.session.vars['practice_draw_count'] - 1 class BeforeOfficialRounds(Page): def is_displayed(self): return self.session.vars['practice_draw_count'] == -1 def before_next_page(self): for round in self.player.in_previous_rounds(): round.subsession.first_draw_rank = 0 round.subsession.second_draw_rank = 0 self.session.vars['practice_draw_count'] = -2 class FirstCardDrawing(Page): def is_displayed(self): return self.session.vars['practice_draw_count'] == -2 and \ self.session.vars['draw_count'] >= 2 form_model = Player form_fields = ['first_draw_accepted'] def vars_for_template(self): self.player.highest_hands() def before_next_page(self): self.session.vars['draw_count'] = self.session.vars['draw_count'] - 1 class SecondCardDrawing(Page): def is_displayed(self): return (self.session.vars['practice_draw_count'] == -2 and self.player.first_draw_accepted and self.session.vars['draw_count'] >= 1) or \ (not self.player.first_draw_accepted and self.session.vars['draw_count'] == 1) def before_next_page(self): self.player.highest_hands() self.session.vars['draw_count'] = self.session.vars['draw_count'] - 1 class PracticeResults(Page): def is_displayed(self): # return self.round_number == Constants.num_rounds return self.session.vars['practice_draw_count'] <= 1 and \ self.session.vars['draw_count'] == 20 and \ not self.session.vars['practice_draw_count'] == -2 def before_next_page(self): self.session.vars['practice_draw_count'] = -1 def vars_for_template(self): self.player.highest_hands() class ScoreInformation(Page): def is_displayed(self): # return self.round_number == Constants.num_rounds return self.session.vars['practice_draw_count'] <= 1 and \ self.session.vars['draw_count'] == 20 and \ not self.session.vars['practice_draw_count'] == -2 def before_next_page(self): self.session.vars['practice_draw_count'] = -1 class Results(Page): def is_displayed(self): # return self.round_number == Constants.num_rounds return self.session.vars['draw_count'] <= 1 def vars_for_template(self): self.player.highest_hands() self.player.calculate_payoff() page_sequence = [ Instructions, Questionnaire, FirstCardDrawingPractice, SecondCardDrawingPractice, BeforeOfficialRounds, PracticeResults, ScoreInformation, FirstCardDrawing, SecondCardDrawing, Results ]