from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import numpy as np author = 'Alexander Schneeberger' doc = """ Rule Following Task """ class Constants(BaseConstants): name_in_url = 'RFT' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): p.RFT_blue_bonus = c(self.session.config['RFT_blue_bonus']) p.RFT_yellow_bonus = c(self.session.config['RFT_yellow_bonus']) p.RFT_pos_blue = np.random.choice(['left', 'right']) class Group(BaseGroup): pass class Player(BasePlayer): # Choice RFT_balls_in_blue = models.IntegerField(min=0, max=20) RFT_balls_in_yellow = models.IntegerField(min=0, max=20) # Background Variables RFT_blue_bonus = models.CurrencyField() RFT_yellow_bonus = models.CurrencyField() RFT_pos_blue = models.StringField() def set_payoff(self): self.payoff = self.RFT_balls_in_blue * self.RFT_blue_bonus + self.RFT_balls_in_yellow * self.RFT_yellow_bonus self.participant.vars['RFT_balls_in_blue'] = self.RFT_balls_in_blue self.participant.vars['RFT_balls_in_yellow'] = self.RFT_balls_in_yellow self.participant.vars['RFT_profit'] = self.payoff