from otree.api import * doc = """ a.k.a. Keynesian beauty contest. Players all guess a number; whoever guesses closest to 2/3 of the average wins. See https://en.wikipedia.org/wiki/Guess_2/3_of_the_average """ class C(BaseConstants): PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 NAME_IN_URL = 'zahlenwahlspiel' jackpot = Currency(10) guess_max = 100 instructions_template = 'zahlenwahlspiel/Instructions.html' instructions_fr_template = 'zahlenwahlspiel/Instructions_fr.html' avg = 24 two_thirds_avg = 16 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): guess = models.FloatField(max=C.guess_max, min=0) is_winner = models.BooleanField() depthlevel = models.IntegerField() language = models.BooleanField( doc="""language""", widget=widgets.RadioSelect, choices=( (True, 'Français'), (False, 'Deutsch'), ) ) randomly = models.BooleanField( doc="""zufallsaugesucht""", widget=widgets.RadioSelect, choices=( (True, 'Ja, rein zufällig'), (False, 'Nein'), ), blank=True ) randomly_fr = models.BooleanField( doc="""suceur aléatoire""", widget=widgets.RadioSelect, choices=( (True, 'Oui, par hasard'), (False, 'Non'), ), blank=True ) # PAGES class LanguageChoice(Page): form_model = 'player' form_fields = ['language'] class Intro(Page): pass class Welcome(Page): pass class Introduction(Page): pass class Guess(Page): form_model = 'player' form_fields = ['guess'] class Deptheliciation(Page): form_model = 'player' form_fields = ['randomly', 'randomly_fr'] def before_next_page(self: Player, **kwargs): if self.field_maybe_none('randomly') or self.field_maybe_none('randomly_fr'): self.depthlevel = 0 else: if self.guess >= 50: self.depthlevel = 0 else: if 33.3 <= self.guess <= 50: self.depthlevel = 1 else: if 22.2 <= self.guess <= 33.3: self.depthlevel = 2 else: if 14.8 <= self.guess <= 22.2: self.depthlevel = 3 else: if 9.8 <= self.guess <= 14.8: self.depthlevel = 4 else: if 6.6 <= self.guess <= 9.8: self.depthlevel = 5 else: if 4.4 <= self.guess <= 6.6: self.depthlevel = 6 else: if 2.9 <= self.guess <= 4.4: self.depthlevel = 7 else: if 0 <= self.guess <= 2.9: self.depthlevel = 8 class ResultsWin(Page): def is_displayed(self: Player): return 16 <= self.guess <= 16.2 class ResultsLoss(Page): def is_displayed(self: Player): return self.guess < 16 or self.guess > 16.2 class Resultsdepth(Page): def vars_for_template(self: Player): return { 'depthlevel': self.depthlevel } page_sequence = [LanguageChoice, Intro, Guess, Deptheliciation, ResultsWin, ResultsLoss, Resultsdepth]