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 = 'ee1740721_2' players_per_group = 4 num_rounds = 1 fair = c(5) unfair_high = c(9) unfair_low = c(1) punishment_price = c(1) class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_payoffs(self): punishment_number = random.randint(3, 4) d = self.get_player_by_id(1) de = self.get_player_by_id(2) if punishment_number == 3: p = self.get_player_by_id(3) r = self.get_player_by_id(4) if punishment_number == 4: p = self.get_player_by_id(4) r = self.get_player_by_id(3) players = self.get_players() if d.delegation_choice: if de.distribution_choice: for g in players: g.assignment += Constants.fair else: d.assignment += Constants.unfair_high de.assignment += Constants.unfair_high p.assignment += Constants.unfair_low r.assignment += Constants.unfair_low else: for g in players: g.assignment += Constants.fair if p.request_punishment: p.punishment_cost += Constants.punishment_price if punishment_number == 3: d.dictator_punishment += self.get_player_by_id(3).punishment_A if punishment_number == 4: d.dictator_punishment += self.get_player_by_id(4).punishment_A if punishment_number == 3: de.delegee_punishment += self.get_player_by_id(3).punishment_B if punishment_number == 4: de.delegee_punishment += self.get_player_by_id(4).punishment_B if punishment_number == 3: r.recipient_punishment += self.get_player_by_id(3).punishment_C if punishment_number == 4: r.recipient_punishment += self.get_player_by_id(4).punishment_C d.payoff = d.assignment - d.dictator_punishment de.payoff = de.assignment - de.delegee_punishment p.payoff = p.assignment - p.punishment_cost r.payoff = r.assignment - r.recipient_punishment class Player(BasePlayer): delegation_choice = models.BooleanField(label="Do you want to delegate the choice?", choices=[[True, "Yes"], [False, "No"]], widget=widgets.RadioSelect) distribution_choice = models.BooleanField(label="How do you want to distribute the resources?", choices=[[True, "Fairly"], [False, "Unfairly"]], widget=widgets.RadioSelect) request_punishment = models.BooleanField(label="Do you want to punish any other player?", choices=[[True, "Yes"], [False, "No"]], widget=widgets.RadioSelect) punishment_A = models.IntegerField(label="How many points do you want to subtract to player A?", initial=0, min=0, max=7, ) punishment_B = models.IntegerField(label="How many points do you want to subtract to the player B?", initial=0, min=0, max=7, ) punishment_C = models.IntegerField(label="How many points do you want to subtract to the player C?", initial=0, min=0, max=7, ) assignment = models.CurrencyField(initial=0) dictator_punishment = models.CurrencyField(initial=0) delegee_punishment = models.CurrencyField(initial=0) recipient_punishment = models.CurrencyField(initial=0) punishment_cost = models.CurrencyField(initial=0)