from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random doc = """ 3 firms complete in a market by setting prices for homogenous goods. See "Kruse, J. B., Rassenti, S., Reynolds, S. S., & Smith, V. L. (1994). Bertrand-Edgeworth competition in experimental markets. Econometrica: Journal of the Econometric Society, 343-371." """ class Constants(BaseConstants): players_per_group = 3 name_in_url = 'bertrand2_30r' num_rounds = 30 instructions_template = 'bertrand2_30r/Instructions.html' maximum_price = c(100) class Subsession(BaseSubsession): pass class Group(BaseGroup): winning_price = models.CurrencyField() num_winners = models.IntegerField() def set_payoffs(self): 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] self.num_winners = len(winners) for p in winners: p.is_winner = True p.payoff = p.price / self.num_winners for p in players: if p.is_winner == False: p.payoff = c(0) class Player(BasePlayer): is_winner = models.BooleanField(initial=False) age = models.IntegerField(min=15, max=100, label="Your age:") sex = models.IntegerField( choices=[ [1, 'Female'], [2, 'Male'], [3, 'Others'], ] ) edu = models.IntegerField( choices=[ [1, 'High school'], [2, 'Some college'], [3, 'Associate degree'], [4, 'Bachelor\'s degree'], [5, 'Master\'s degree'], [6, 'Doctoral degree'], ] ) price = models.CurrencyField( min=0, max=Constants.maximum_price, doc="""Price player offers to sell product for""", )