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 = 'AtC_game' players_per_group = None num_rounds = 2 endowment = c(100) lo_value = 0 hi_value = 99 shift_value = 20 instructions_template = 'AtC_game/Instruction_summary.html' class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): if self.round_number == 1: p.shifted = random.random() < 0.5 if self.round_number == 2: p.shifted = not p.in_round(1).shifted p.value = random.randint(Constants.lo_value, Constants.hi_value) + Constants.shift_value * p.shifted class Group(BaseGroup): pass class Player(BasePlayer): bid = models.IntegerField( min=Constants.lo_value, max=Constants.hi_value + Constants.shift_value, label="What is your bid for this round?" ) value = models.IntegerField() shifted = models.BooleanField() round_payoff = models.IntegerField() def set_payoff(self): if self.bid >= self.value: self.payoff = (Constants.endowment - self.bid + 1.5 * self.value)/5 self.participant.vars['AtC_payoff'] += (Constants.endowment - self.bid + 1.5 * self.value)/5 self.round_payoff = int(Constants.endowment - self.bid + 1.5 * self.value) elif self.bid < self.value: self.participant.vars['AtC_payoff'] += Constants.endowment/5 self.round_payoff = int(Constants.endowment) self.payoff = Constants.endowment/5;