from otree.api import * c = cu doc = '\nIn Cournot competition, firms simultaneously decide the units of products to\nmanufacture. The unit selling price depends on the total units produced. In\nthis implementation, there are 2 firms competing for 1 period.\n' class Constants(BaseConstants): name_in_url = 'cournot' players_per_group = 2 num_rounds = 1 total_capacity = 60 max_units_per_player = 30 my_constant = False instructions_template = 'cournot/instructions.html' class Subsession(BaseSubsession): pass def set_payoffs(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 class Group(BaseGroup): unit_price = models.CurrencyField() total_units = models.IntegerField(doc='Total units produced by all players') set_payoffs = set_payoffs def other_player(player): group = player.group return player.get_others_in_group()[0] class Player(BasePlayer): units = models.IntegerField(doc='Quantity of units to produce', label='How many units will you produce from 0 to 30', max=Constants.max_units_per_player, min=0) other_player = other_player class Introduction(Page): form_model = 'player' class Decide(Page): form_model = 'player' form_fields = ['units'] class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' body_text = 'Waiting for the other participant to decide.' class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player): return dict(other_player_units=other_player(player).units) page_sequence = [Introduction, Decide, ResultsWaitPage, Results]