from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random class Constants(BaseConstants): name_in_url = 'gamble_practice_v2' players_per_group = None num_rounds = 3 initial_amount = 6 class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: paying_round_pract2 = random.randint(1, 3) self.session.vars['paying_round_pract2'] = paying_round_pract2 class Group(BaseGroup): pass class Player(BasePlayer): option_choice_1 = models.BooleanField(initial = False) option_choice_2 = models.BooleanField() C = models.FloatField() w0 = models.FloatField() w1 = models.FloatField() min_g1 = models.FloatField() max_g1 = models.FloatField() C2 = models.FloatField() w2 = models.FloatField() min_g2 = models.FloatField() max_g2 = models.FloatField() final = models.FloatField() k1 = models.FloatField() k2 = models.FloatField() id_number = models.IntegerField(label = "Your ID", min=1, max=20) def stage_1(self): ### define first stage if self.round_number == 1: self.w0 = Constants.initial_amount self.C = round(random.uniform(-0.6, -0.1), 1) self.min_g1 = round(self.C - random.uniform(-0.3, 0.1), 1) self.max_g1 = round(self.C + random.uniform(0.35, 1.2), 1) self.k1 = round(random.uniform(self.min_g1, self.max_g1), 1) if self.round_number == 2: self.w0 = Constants.initial_amount self.C = round(random.uniform(0, 0.6), 1) self.min_g1 = round(self.C - random.uniform(1.2, 0.3), 1) self.max_g1 = round(self.C + random.uniform(0.01, 0.3), 1) self.k1 = round(random.uniform(self.min_g1, self.max_g1), 1) if self.round_number == 3: self.w0 = Constants.initial_amount self.C = round(random.uniform(-0.6, 0.6), 1) self.min_g1 = round(self.C - random.uniform(0.01, 0.6), 1) self.max_g1 = round(self.C + random.uniform(0.01, 1.2), 1) self.k1 = round(random.uniform(self.min_g1, self.max_g1), 1) self.w1 = self.w0 + self.k1 def stage_2(self): ### define second stage if self.round_number == 1: self.min_g2 = round(self.C - random.uniform(0.01, 0.6), 1) self.max_g2 = round(self.C + random.uniform(0.01, 1.2), 1) self.k2 = round(random.uniform(self.min_g2, self.max_g2), 1) if self.round_number == 2: self.min_g2 = round(self.C - random.uniform(-0.3, 0.1), 1) self.max_g2 = round(self.C + random.uniform(0.2, 1.2), 1) self.k2 = round(random.uniform(self.min_g2, self.max_g2), 1) if self.round_number == 3: self.min_g2 = round(self.C - random.uniform(0.3, 1.2), 1) self.max_g2 = round(self.C + random.uniform(-0.1, 0.2), 1) self.k2 = round(random.uniform(self.min_g2, self.max_g2), 1) self.w2 = self.w0 + self.k2 def final_result(self): if (self.option_choice_1): if (self.option_choice_2): self.final = self.w2 else: self.final = self.w1 else: self.final = self.w0 + self.C def payoff(self): self.winning_round = self.session.vars['paying_round']