from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'simple_auction' players_per_group = 4 num_rounds = 1 fix_pay = c(20) class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): p.valuation = random.randint(0, 100) #Before the session starts, everyone gets assigned an induced valuation. class Group(BaseGroup): winner_id = models.IntegerField() #Saving ID of winner in data def set_payoffs(self): players = self.get_players() bids = [p.bid for p in players] max_bid = max(bids) self.winner_id = random.choice([p.id_in_group for p in players if p.bid == max_bid]) #random choice from those who made the max bid. for p in players: if p.id_in_group == self.winner_id: p.winner = True p.payoff = Constants.fix_pay + (p.valuation - p.bid) else: p.payoff = Constants.fix_pay class Player(BasePlayer): valuation = models.CurrencyField() bid = models.CurrencyField(label="How much do you want to bid?", min=0, max=100) winner = models.BooleanField(initial=False)