from otree.api import ( Page, WaitPage, models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from django import forms class Constants(BaseConstants): name_in_url = 'bargaining' players_per_group = None num_rounds = 1 instructions_template = 'bargaining/instructions.html' amount_shared = c(100) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): heads_tokens = models.CurrencyField() class TokenAllocation(Page): form_model = 'player' form_fields = ['heads_tokens'] def get_form_fields_with_widgets(self): return { 'heads_tokens': forms.widgets.NumberInput( attrs={'type': 'range', 'orient': 'vertical', 'step': 1, 'min': 0, 'max': 100}) } def vars_for_template(self: Player): tails_tokens = 100 - self.heads_tokens money_value = (100 - self.heads_tokens) ** 2 return { 'total_tokens': 100, 'tails_tokens': tails_tokens, 'money_value': money_value } @staticmethod def before_next_page(self: Player, timeout_happened): self.tails_tokens = 100 - self.heads_tokens def js_vars(self): return dict() def js_includes(self): return ['bargaining/slider_adjustment.js'] # Replace 'my_app_name' with your app name class FlipCoin(Page): def vars_for_template(self: Player): return { 'outcome': self.flip_outcome(), 'winnings': self.calculate_winnings() } class Results(Page): pass page_sequence = [ TokenAllocation, FlipCoin, Results ]