from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '\n2 firms complete in a market by setting prices for homogenous goods.\n\nSee "Kruse, J. B., Rassenti, S., Reynolds, S. S., & Smith, V. L. (1994).\nBertrand-Edgeworth competition in experimental markets.\nEconometrica: Journal of the Econometric Society, 343-371."\n' class Constants(BaseConstants): name_in_url = 'bertrand' players_per_group = 2 num_rounds = 2 maximum_price = c(200) instructions_template = 'bertrand/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): winning_price = models.CurrencyField() def set_payoffs(self): import random players = self.get_players() self.winning_price = min([p.price for p in players]) winners = [p for p in players if p.price == self.winning_price] winner = random.choice(winners) for p in players: if p == winner: p.is_winner = True p.payoff = p.price else: p.is_winner = False p.payoff = c(0) class Player(BasePlayer): price = models.CurrencyField(doc='Price player offers to sell product for', max=Constants.maximum_price, min=0) is_winner = models.BooleanField()