from otree.api import * 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 = 'holt_2' players_per_group = 2 num_rounds = 10 instructions_template = 'jikken_holt_2/instructions.html' # Total production capacity of all players total_capacity = 16 class Subsession(BaseSubsession): pass class Group(BaseGroup): unit_price = models.IntegerField() total_units = models.IntegerField(doc="""Total units produced by all players""") class Player(BasePlayer): units = models.IntegerField( min=1, max=8, doc="""Quantity of units to produce""", label="1~8の整数であなたの生産量を決定してください。(半角)" ) # FUNCTIONS def creating_session(subsession: Subsession): if subsession.round_number == 1: subsession.group_randomly() else: subsession.group_like_round(1) def set_payoffs(group: Group): players = group.get_players() group.total_units = sum([p.units for p in players]) group.unit_price = Constants.total_capacity - group.total_units for p in players: p.payoff = group.unit_price * p.units def other_player(player: Player): return player.get_others_in_group()[0] # PAGES class Introduction(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Decide(Page): timeout_seconds = 150 form_model = 'player' form_fields = ['units'] class ResultsWaitPage(WaitPage): body_text = "他の参加者の選択を待っています。" after_all_players_arrive = 'set_payoffs' class Results(Page): @staticmethod def vars_for_template(player: Player): return dict(other_player_units=other_player(player).units) page_sequence = [Introduction, Decide, ResultsWaitPage, Results]