from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Francisco' doc = """ Your app description """ # Constants are the paraemters of the game shared by everyone class Constants(BaseConstants): name_in_url = 'my_quality_game' players_per_group = 2 num_rounds = 4 max_quality = 1. min_quality = 0. #price_1 = 2. #price_2 = 1. # Parameters of uncertainty q = 1 kh = 1 #instructions_template = 'my_quality/instructions.html' class Subsession(BaseSubsession): def creating_session(self): #if self.round_number != 0: # # reverse the roles # matrix = self.get_group_matrix() # for row in matrix: # row.reverse() # self.set_group_matrix(matrix) if self.round_number != 10000: self.group_randomly() print(self.get_group_matrix()) class Group(BaseGroup): # We can use the main field here since it is a sequential game; if simultaneous, set this in player vh = models.FloatField(min=Constants.min_quality, max=Constants.max_quality, #widget = widgets.Slider, label="What is the quality label of your product?") v_guess_l = models.FloatField(min=Constants.min_quality, max=Constants.max_quality, label="Guess how much you think your competitior will set his quality?") vl = models.FloatField(min=Constants.min_quality, max=Constants.max_quality, #widget=widgets.SliderInput(), label="What is the quality label of your product?") def set_payoffs(self): p1 = (2 * Constants.kh**2 * self.vh**2 * (Constants.kh * self.vh - self.vl))\ /((1 + (Constants.kh - 1) * Constants.q) * (4 * self.vh - self.vl)) p2 = (Constants.k * self.vl * (self.vh - self.vl))\ /((1 + (Constants.k - 1) * Constants.q) * (4 * self.vh - self.vl)) D1_R = 1 - (p1-p2)/(self.vh - self.vl) D2_R = (p1-p2)/(self.vh - self.vl) - (p2)/(self.vl) D1_W = 1 - (p1-p2)/(Constants.k*self.vh - Constants.k*self.vl) D2_W = (p1-p2)/(Constants.k*self.vh - Constants.k*self.vl) - (p2)/(Constants.k*self.vl) play1 = self.get_player_by_id(1) play2 = self.get_player_by_id(2) play1.payoff = c(p1*(Constants.q*D1_R+(1-Constants.q)*D1_W)) play2.payoff = c(p2*(Constants.q*D2_R+(1-Constants.q)*D2_W)) print(p1) print(p2) print(D1_R) print(D2_R) print(D1_W) print(D2_W) print(play1.payoff) print(play2.payoff) class Player(BasePlayer): def role(self): if self.id_in_group == 1: return 'Leader' if self.id_in_group == 2: return 'Follower'