from otree.api import * import random author = "Jihoon Jun" doc = """ Dice Guess Game """ class Constants(BaseConstants): name_in_url = 'dice_task' players_per_group = None num_rounds = 6 def dice_outcome(round_number): return random.randint(1, 6) paid_round = random.randint(1, 6) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): guess = models.IntegerField(choices=[[0, "2 or lower"], [1, "3 or higher"]], widget=widgets.RadioSelectHorizontal, label='') paid_round = models.IntegerField() final_payoff = models.FloatField() def result_calculator(self): if self.round_number == Constants.paid_round: if self.guess == 0 and Constants.dice_outcome(self.round_number) <= 2: self.final_payoff = 100 elif self.guess == 1 and Constants.dice_outcome(self.round_number) >= 3: self.final_payoff = 100 else: self.final_payoff = 20 else: self.final_payoff = 0