from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) 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 = 2 total_capacity = 60 max_units_per_player = 30 instructions_template = 'cournot/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): unit_price = models.CurrencyField() total_units = models.IntegerField(doc='Total units produced by all players') def set_payoffs(self): players = self.get_players() self.total_units = sum([p.units for p in players]) self.unit_price = Constants.total_capacity - self.total_units for p in players: p.payoff = self.unit_price * p.units class Player(BasePlayer): units = models.IntegerField(doc='Quantity of units to produce', max=Constants.max_units_per_player, min=0) def other_player(self): return self.get_others_in_group()[0]