from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ In Cournot competition, firms simultaneously decide the units of products to manufacture. The unit selling price depends on the total units produced. In this implementation, there are 2 firms competing for 1 period. """ class Constants(BaseConstants): name_in_url = 'cournot' players_per_group = 2 num_rounds = 20 instructions_template = 'cournot_1/instructions.html' # Total production capacity of all players total_capacity = 160 max_units_per_player = 100 A_List=(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2) B_List=(2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1) class Subsession(BaseSubsession): def creating_session(self): self.group_randomly(fixed_id_in_group=True) class Group(BaseGroup): seisanSelect = models.IntegerField( choices=[ [1, '自社製造'], [2, '委託製造'], ], label = "どちらにするか選んでください" ) chabaSelect = models.IntegerField( choices=[ [1, '自社調達'], [2, '他社調達'], ], label = "どちらにするか選んでください" ) price = models.IntegerField() seisan_units = models.IntegerField( min=2, max=10, doc="""Quantity of units to produce""", label="生産量を入力してください(2~10の間で入力してください)" ) chaba_units = models.IntegerField( min=2, max=10, doc="""Quantity of units to produce""", label="生産量を入力してください(2~10の間で入力してください)" ) def role(self): return {1: 'A', 2: 'B'}[self.id_in_group] total_units = models.IntegerField(doc="""Total units produced by all players""") seisan_point = models.CurrencyField() # プレイヤー1の利得 chaba_point = models.CurrencyField() # プレイヤー2の利得 def set_payoffs(self): self.total_units = (self.chaba_units + self.seisan_units) * 10 self.price = Constants.total_capacity - (self.seisan_units + self.chaba_units) * 10 if self.price < 0: self.price = 0 else: self.price = Constants.total_capacity - (self.seisan_units + self.chaba_units) * 10 if self.seisanSelect == 1 and self.chabaSelect == 1: self.seisan_point = self.price * self.seisan_units * 10 - 20 * self.seisan_units * 10- 1000 self.chaba_point = self.price * self.chaba_units * 10 - 63 * self.chaba_units * 10 elif self.seisanSelect == 1 and self.chabaSelect == 2: self.seisan_point = self.price * self.seisan_units * 10 - 20 * self.seisan_units * 10 - 1000 self.chaba_point = self.price * self.chaba_units * 10 - 72 * self.chaba_units * 10 elif self.seisanSelect == 2 and self.chabaSelect == 1: self.seisan_point = self.price * self.seisan_units * 10 - 20 * self.seisan_units * 10 - 600 self.chaba_point = self.price * self.chaba_units * 10 - 63 * self.chaba_units * 10 else: self.seisan_point = self.price * self.seisan_units * 10 - 20 * self.seisan_units * 10 - 600 self.chaba_point = self.price * self.chaba_units * 10 - 72 * self.chaba_units * 10 p1 = self.get_player_by_id(Constants.A_List[self.round_number - 1]) p2 = self.get_player_by_id(Constants.B_List[self.round_number - 1]) p1.payoff = self.seisan_point p2.payoff = self.chaba_point class Player(BasePlayer): def role(self): return {1: 'A', 2: 'B'}[self.id_in_group]