from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = 'training before the game' class Constants(BaseConstants): name_in_url = 'training' players_per_group = None num_rounds = 5 num_sites = 3 rhino_distribution = (0.2, 0.8, 0.5) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): next_site = models.IntegerField(choices=[[1, 'Site 1'], [2, 'Site 2'], [3, 'Site 3']], label='Which site would you like to visit for this round?', widget=widgets.RadioSelect) most_likely = models.StringField(choices=[['1', 'Site 1'], ['2', 'Site 2'], ['3', 'Site 3'], ['4', 'Site 4'], ['5', 'Site 5']], label='Which site is the most likely to have a rhino?', widget=widgets.RadioSelect) least_likely = models.StringField(choices=[['1', 'Site 1'], ['2', 'Site 2'], ['3', 'Site 3'], ['4', 'Site 4'], ['5', 'Site 5']], label='Which site is the least likely to have a rhino?', widget=widgets.RadioSelect) times = models.IntegerField(label='If you visited site 1 a hundred times, approximately how many times do you expect to see a rhino?', max=100, min=0) def get_payoff(self): import random i = self.next_site # poacher j = random.randint(1, Constants.num_sites) # ranger r = random.random() < Constants.rhino_distribution[i-1] if i!=j and r: self.payoff = 1 elif i == j: self.payoff = -1 else: self.payoff = 0 def get_payment(self): return max(round(int(self.participant.payoff) * 0.1,2),0) + 1 def get_bonus(self): return max(round(int(self.participant.payoff) * 0.1,2),0)