from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Francisco' doc = """ This game is a modification of the duopoly version of Musa-Rosen. See Scott and Sesmero (2019) for more details. """ # Constants are the paraemters of the game shared by everyone class Constants(BaseConstants): name_in_url = 'my_quality_game_training_bench_kl_065_discrete_choice' players_per_group = None num_rounds = 2 max_quality_high = 50. min_quality_high = 16. max_quality_low = 15. min_quality_low = 2. max_price_high = 2700. min_price_high = 590. max_price_low = 150. min_price_low = 50. # Parameters of uncertainty kh = 1. kl =0.65 #instructions_template = 'my_quality/instructions.html' # ratio of optimal qualities under kh r = 1 # Cost parameters alpha = 2 class Subsession(BaseSubsession): pass class Group(BaseGroup): # STILL HAVE TO ADD A BUTTON TO OPT OUT OF THE ROUND # We can use the main field here since it is a sequential game; if simultaneous, set this in player #### PAGE 1, leader def set_payoffs(self): # These are the demand formulas (we are using pl_guess_2 b/c it is randomly generate by bot) Dh = (100 - (self.player.ph - self.player.pl_guess_2) / (Constants.kh * self.player.vh - self.player.vl)) / (100 - 0) #Dl = ((self.player.ph - self.pl_guess_2) / (Constants.kh * self.vh - self.vl) - (self.pl_guess_2) / (self.vl)) / (100 - 0) # Calculate the payment # print(self.subsession.round_number) if self.player.ph * Dh - (self.vh ** Constants.alpha) / Constants.alpha > 0.0: self.player.payoff = (self.player.ph * Dh - (self.vh ** Constants.alpha) / Constants.alpha) else: self.player.payoff = 0 print(self.player.payoff) # if self.subsession.round_number == self.session.vars['paying_round']: class Player(BasePlayer): #### PAGE 3, leader's prices vh = models.FloatField(min=Constants.min_quality_high, max=Constants.max_quality_high, # widget = widgets.Slider, label="What is the quality label of your product?") vl_guess_1 = models.FloatField(min=Constants.min_quality_low, max=Constants.max_quality_low, label="Guess how much you think your competitior will set his quality?") ph_guess_1 = models.FloatField(min=Constants.min_price_high, max=Constants.max_price_high, label="Given quality choices, how much you will set your prices?") pl_guess_1 = models.FloatField(min=Constants.min_price_low, max=Constants.max_price_low, label="Guess how much you think your competitor will set prices?") #### PAGE 1, follower vl = models.FloatField(min=Constants.min_quality_low, max=Constants.max_quality_low, # widget=widgets.SliderInput(), label="What is the quality label of your product?") ph_guess_2 = models.FloatField(min=Constants.min_price_high, max=Constants.max_price_high, label="Guess how much you think your competitor will set prices") pl_guess_2 = models.FloatField(min=Constants.min_price_low, max=Constants.max_price_low, label="Given quality choices, how much you will set your prices?") ph = models.FloatField(min=Constants.min_price_high, max=Constants.max_price_high, label="Given quality choices, how much you will set your prices?") # pl_guess_3 = models.FloatField(min=Constants.min_price_low, # max=Constants.max_price_low, # label="Guess how much you think your competitor will set prices?") ##### PAGE 4, follower's price # ph_guess_3 = models.FloatField(min=Constants.min_price_high, # max=Constants.max_price_high, # label="Guess how much you think your competitor will set prices") pl_guess_3 = models.FloatField(min=Constants.min_price_low, max=Constants.max_price_low, label="Given quality choices, how much you will set your prices?")