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_changed' players_per_group = 3 num_rounds = 7 instructions_template = 'cournot_changed/instructions.html' # ここが 変数a total_capacity = 120 max_units_per_player = int(total_capacity / players_per_group) class Subsession(BaseSubsession): pass # def creating_session(self): # if self.round_number == 1: # self.group_randomly() # else: # self.group_like_round(1) # if self.round_number == 1 or self.round_number == 8 or self.round_number == 15: # self.group_randomly(fixed_id_in_group=True) # elif self.round_number == 2: # self.group_like_round(1) # elif self.round_number == 3: # self.group_like_round(1) # elif self.round_number == 4: # self.group_like_round(1) # elif self.round_number == 5: # self.group_like_round(1) # elif self.round_number == 6: # self.group_like_round(1) # elif self.round_number == 7: # self.group_like_round(1) # elif self.round_number == 9: # self.group_like_round(8) # elif self.round_number == 10: # self.group_like_round(8) # elif self.round_number == 11: # self.group_like_round(8) # elif self.round_number == 12: # self.group_like_round(8) # elif self.round_number == 13: # self.group_like_round(8) # elif self.round_number == 14: # self.group_like_round(8) # else: # self.group_like_round(15) class Group(BaseGroup): p1_entry = models.CharField(initial='E', choices=[['E', 'はい、参入します'], ['NE', 'いいえ、参入しません']], label='参入しますか。', ) p1_entry_check = models.CharField(initial='1', choices=[['0', '戻る(修正する)'], ['1', '次に進む']], label='前のページに戻り、修正しますか。次に進みますか。', ) p2_sosi = models.CharField(initial='N', choices=[['Y', 'はい、追い出したい'], ['N', 'いいえ、追い出さなくても良い']], label='参入企業を「追い出したい」ですか。', ) p2_sosi_check = models.CharField(initial='1', choices=[['0', '戻る(修正する)'], ['1', '次に進む']], label='前のページに戻り、修正しますか。次に進みますか。', ) p3_sosi = models.CharField(initial='N', choices=[['Y', 'はい、追い出したい'], ['N', 'いいえ、追い出さなくても良い']], label='参入企業を「追い出したい」ですか。', ) p3_sosi_check = models.CharField(initial='1', choices=[['0', '戻る(修正する)'], ['1', '次に進む']], label='前のページに戻り、修正しますか。次に進みますか。', ) p2_sosi_sannkou= models.CharField(initial='N', choices=[['Y', 'はい'], ['N', 'いいえ']], label='先ほど参入企業が参入した場合、あなたは参入企業を「追い出したい」を選択しましたか。', ) p3_sosi_sannkou= models.CharField(initial='N', choices=[['Y', 'はい'], ['N', 'いいえ']], label='先ほど参入企業が参入した場合、あなたは参入企業を「追い出したい」を選択しましたか。', ) p1_unit = models.IntegerField(initial=30, choices=[5, 10, 15, 20, 25, 30], label='生産量を以下から選択してください。', ) p1_unit_check = models.CharField(initial='1', choices=[['0', '戻る(修正する)'], ['1', '次に進む']], label='前のページに戻り、修正しますか。次に進みますか。', ) p2_unit_Y = models.IntegerField(initial=55, choices=[55, 65, 75, 85, 95, 105], label='生産量を以下から選択してください。', ) p2_unit_Y_check = models.CharField(initial='1', choices=[['0', '戻る(修正する)'], ['1', '次に進む']], label='前のページに戻り、修正しますか。次に進みますか。', ) p3_unit_Y = models.IntegerField(initial=55, choices=[55, 65, 75, 85, 95, 105], label='生産量を以下から選択してください。', ) p3_unit_Y_check = models.CharField(initial='1', choices=[['0', '戻る(修正する)'], ['1', '次に進む']], label='前のページに戻り、修正しますか。次に進みますか。', ) p2_unit_N = models.IntegerField(initial=30, choices=[5, 10, 15, 20, 25, 30], label='生産量を以下から選択してください。', ) p2_unit_N_check = models.CharField(initial='1', choices=[['0', '戻る(修正する)'], ['1', '次に進む']], label='前のページに戻り、修正しますか。次に進みますか。', ) p3_unit_N = models.IntegerField(initial=30, choices=[5, 10, 15, 20, 25, 30], label='生産量を以下から選択してください。', ) p3_unit_N_check = models.CharField(initial='1', choices=[['0', '戻る(修正する)'], ['1', '次に進む']], label='前のページに戻り、修正しますか。次に進みますか。', ) p2_unit_NE = models.IntegerField(initial=40, choices=[10, 20, 30, 40, 50, 60, 70], label='生産量を以下から選択してください。', ) p2_unit_NE_check = models.CharField(initial='1', choices=[['0', '戻る(修正する)'], ['1', '次に進む']], label='前のページに戻り、修正しますか。次に進みますか。', ) p3_unit_NE = models.IntegerField(initial=40, choices=[10, 20, 30, 40, 50, 60, 70], label='生産量を以下から選択してください。', ) p3_unit_NE_check = models.CharField(initial='1', choices=[['0', '戻る(修正する)'], ['1', '次に進む']], label='前のページに戻り、修正しますか。次に進みますか。', ) unit_price_NE = models.CurrencyField() total_units_NE = models.IntegerField(doc="""Total units produced by all players""") p1_payoff_NE = models.IntegerField() p2_payoff_NE = models.IntegerField() p3_payoff_NE = models.IntegerField() p1_point_NE = models.IntegerField() p2_point_NE = models.IntegerField() p3_point_NE = models.IntegerField() unit_weight_NE = models.IntegerField() unit_price_ENN = models.CurrencyField() total_units_ENN = models.IntegerField(doc="""Total units produced by all players""") p1_payoff_ENN = models.IntegerField() p2_payoff_ENN = models.IntegerField() p3_payoff_ENN = models.IntegerField() p1_point_ENN = models.IntegerField() p2_point_ENN = models.IntegerField() p3_point_ENN = models.IntegerField() unit_weight_ENN = models.IntegerField() unit_price_ENY = models.CurrencyField() total_units_ENY = models.IntegerField(doc="""Total units produced by all players""") p1_payoff_ENY = models.IntegerField() p2_payoff_ENY = models.IntegerField() p3_payoff_ENY = models.IntegerField() p1_point_ENY = models.IntegerField() p2_point_ENY = models.IntegerField() p3_point_ENY = models.IntegerField() unit_weight_ENY = models.IntegerField() unit_price_EYN = models.CurrencyField() total_units_EYN = models.IntegerField(doc="""Total units produced by all players""") p1_payoff_EYN = models.IntegerField() p2_payoff_EYN = models.IntegerField() p3_payoff_EYN = models.IntegerField() p1_point_EYN = models.IntegerField() p2_point_EYN = models.IntegerField() p3_point_EYN = models.IntegerField() unit_weight_EYN = models.IntegerField() unit_price_EYY = models.CurrencyField() total_units_EYY = models.IntegerField(doc="""Total units produced by all players""") p1_payoff_EYY = models.IntegerField() p2_payoff_EYY = models.IntegerField() p3_payoff_EYY = models.IntegerField() p1_point_EYY = models.IntegerField() p2_point_EYY = models.IntegerField() p3_point_EYY = models.IntegerField() unit_weight_EYY = models.IntegerField() def set_payoffs(self): players = self.get_players() p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p3 = self.get_player_by_id(3) self.total_units_NE = self.p2_unit_NE + self.p3_unit_NE self.unit_price_NE = Constants.total_capacity - self.total_units_NE self.p1_payoff_NE = 0 self.p2_payoff_NE = self.unit_price_NE * self.p2_unit_NE self.p3_payoff_NE = self.unit_price_NE * self.p3_unit_NE self.p1_point_NE = 30 self.p2_point_NE = 30 + self.unit_price_NE * self.p2_unit_NE self.p3_point_NE = 30 + self.unit_price_NE * self.p3_unit_NE if self.p2_unit_NE + self.p3_unit_NE >= 120: self.unit_weight_NE = 0 else: self.unit_weight_NE = 1 self.total_units_ENN = self.p1_unit + self.p2_unit_N + self.p3_unit_N self.unit_price_ENN = Constants.total_capacity - self.total_units_ENN self.p1_payoff_ENN = self.unit_price_ENN * self.p1_unit self.p2_payoff_ENN = self.unit_price_ENN * self.p2_unit_N self.p3_payoff_ENN = self.unit_price_ENN * self.p3_unit_N self.p1_point_ENN = 30 + self.unit_price_ENN * self.p1_unit -25 self.p2_point_ENN = 30 + self.unit_price_ENN * self.p2_unit_N self.p3_point_ENN = 30 + self.unit_price_ENN * self.p3_unit_N if self.p1_unit + self.p2_unit_N + self.p3_unit_N >= 120: self.unit_weight_ENN = 0 else: self.unit_weight_ENN = 1 self.total_units_ENY = self.p1_unit + self.p2_unit_N + self.p3_unit_Y self.unit_price_ENY = Constants.total_capacity - self.total_units_ENY self.p1_payoff_ENY = self.unit_price_ENY * self.p1_unit self.p2_payoff_ENY = self.unit_price_ENY * self.p2_unit_N self.p3_payoff_ENY = self.unit_price_ENY * self.p3_unit_Y self.p1_point_ENY = 30 + self.unit_price_ENY * self.p1_unit -25 self.p2_point_ENY = 30 + self.unit_price_ENY * self.p2_unit_N self.p3_point_ENY = 30 + self.unit_price_ENY * self.p3_unit_Y if self.p1_unit + self.p2_unit_N + self.p3_unit_Y >= 120: self.unit_weight_ENY = 0 else: self.unit_weight_ENY = 1 self.total_units_EYN = self.p1_unit + self.p2_unit_Y + self.p3_unit_N self.unit_price_EYN = Constants.total_capacity - self.total_units_EYN self.p1_payoff_EYN = self.unit_price_EYN * self.p1_unit self.p2_payoff_EYN = self.unit_price_EYN * self.p2_unit_Y self.p3_payoff_EYN = self.unit_price_EYN * self.p3_unit_N self.p1_point_EYN = 30 + self.unit_price_EYN * self.p1_unit - 25 self.p2_point_EYN = 30 + self.unit_price_EYN * self.p2_unit_Y self.p3_point_EYN = 30 + self.unit_price_EYN * self.p3_unit_N if self.p1_unit + self.p2_unit_Y + self.p3_unit_N >= 120: self.unit_weight_EYN = 0 else: self.unit_weight_EYN = 1 self.total_units_EYY = self.p1_unit + self.p2_unit_Y + self.p3_unit_Y self.unit_price_EYY = Constants.total_capacity - self.total_units_EYY self.p1_payoff_EYY = self.unit_price_EYY * self.p1_unit self.p2_payoff_EYY = self.unit_price_EYY * self.p2_unit_Y self.p3_payoff_EYY = self.unit_price_EYY * self.p3_unit_Y self.p1_point_EYY = 30 + self.unit_price_EYY * self.p1_unit - 25 self.p2_point_EYY = 30 + self.unit_price_EYY * self.p2_unit_Y self.p3_point_EYY = 30 + self.unit_price_EYY * self.p3_unit_Y if self.p1_unit + self.p2_unit_Y + self.p3_unit_Y >= 120: self.unit_weight_EYY = 0 else: self.unit_weight_EYY = 1 class Player(BasePlayer): def role(self): if self.id_in_group == 1: return 'p1' elif self.id_in_group == 2: return 'p2' elif self.id_in_group == 3: return 'p3' # if self.id_in_group == 1 and self.round_number == 1 or self.round_number == 2: # return 'p1' # elif self.id_in_group == 2 and self.round_number == 1 or self.round_number == 2: # return 'p2' # elif self.id_in_group == 3 and self.round_number == 1 or self.round_number == 2: # return 'p3' # elif self.id_in_group == 1 and self.round_number == 3 or self.round_number == 4: # return 'p2' # elif self.id_in_group == 2 and self.round_number == 3 or self.round_number == 4: # return 'p3' # elif self.id_in_group == 3 and self.round_number == 3 or self.round_number == 4: # return 'p1' # elif self.id_in_group == 1 and self.round_number == 5 or self.round_number == 6: # return 'p3' # elif self.id_in_group == 2 and self.round_number == 5 or self.round_number == 6: # return 'p1' # elif self.id_in_group == 3 and self.round_number == 5 or self.round_number == 6: # return 'p2' #or self.round_number == 3 or self.round_number == 4 or self.round_number == 5 or self.round_number == 6 or self.round_number == 7: