from otree.api import * import random import time doc = """ 11-20 request game """ class C(BaseConstants): NAME_IN_URL = 'random2' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 INSTRUCTIONSN1_TEMPLATE = 'random2/instructionsN1.html' INSTRUCTIONSCy1_TEMPLATE = 'random2/instructionsCy1.html' INSTRUCTIONSCo1_TEMPLATE = 'random2/instructionsCo1.html' INSTRUCTIONSN2_TEMPLATE = 'random2/instructionsN2.html' INSTRUCTIONSCy2_TEMPLATE = 'random2/instructionsCy2.html' INSTRUCTIONSCo2_TEMPLATE = 'random2/instructionsCo2.html' INSTRUCTIONS_TEMPLATE = 'random2/instructions.html' CHECKN1_TEMPLATE = 'random2/checktextN1.html' CHECKCy1_TEMPLATE = 'random2/checktextCy1.html' CHECKCo1_TEMPLATE = 'random2/checktextCo1.html' CHECKN2_TEMPLATE = 'random2/checktextN2.html' CHECKCy2_TEMPLATE = 'random2/checktextCy2.html' CHECKCo2_TEMPLATE = 'random2/checktextCo2.html' # Player's reward for the lowest claim""" ADJUSTMENT_ABS = int(0) # Player's deduction for the higher claim # The maximum claim to be requested MAX_AMOUNT = int(20) # The minimum claim to be requested MIN_AMOUNT = int(11) TASKS = ['N1','N2'] NUM_ROUNDS = 1 NUMBERS=[11,12,13,14,15,16,17,18,19,20] class Subsession(BaseSubsession): pass class Group(BaseGroup): lower_claim = models.CurrencyField() class Player(BasePlayer): claimN1 = models.IntegerField( min=C.MIN_AMOUNT, max=C.MAX_AMOUNT, label='', doc=""" """, ) claimCHECKN1 = models.IntegerField( min=11, max=40, label='How many pence would you win?', doc=""" """, ) claimN2 = models.IntegerField( min=C.MIN_AMOUNT, max=C.MAX_AMOUNT, label='', doc=""" """, ) claimCHECKN2 = models.IntegerField( min=11, max=40, label='How many pence would you win?', doc=""" """, ) # FUNCTIONS def creating_session(subsession: Subsession): if subsession.round_number == 1: for p in subsession.get_players(): r=random.randint(0,1) if r==0: version=C.TASKS[0] if r==1: version=C.TASKS[1] p.participant.version=version p.participant.n1=20 p.participant.n2=random.choice(C.NUMBERS) def payoffN1(n1,n2): if n1==n2-1: s=20 else: s=0 return n1+s def payoffN2(n1,n2): if n1==n2-2: s=20 else: s=0 return n1+s # PAGES class Confirmation1(Page): @staticmethod def is_displayed(player: Player): participant = player.participant return participant.version=='N1' class Confirmation2(Page): @staticmethod def is_displayed(player: Player): participant = player.participant return participant.version=='N2' class CheckN1(Page): form_model = 'player' form_fields = ['claimCHECKN1'] @staticmethod def app_after_this_page(player, upcoming_apps): if player.claimCHECKN1!=payoffN1(player.participant.n2,player.participant.n1): return upcoming_apps[-1] @staticmethod def is_displayed(player: Player): participant = player.participant return participant.version=='N1' class CheckN2(Page): form_model = 'player' form_fields = ['claimCHECKN2'] @staticmethod def app_after_this_page(player, upcoming_apps): if player.claimCHECKN2!=payoffN2(player.participant.n2,player.participant.n1): return upcoming_apps[-1] @staticmethod def is_displayed(player: Player): participant = player.participant return participant.version=='N2' class IntroductionN1(Page): @staticmethod def is_displayed(player: Player): participant = player.participant if participant.version=='N1': player.participant.t1=time.time() return participant.version=='N1' class IntroductionN2(Page): @staticmethod def is_displayed(player: Player): participant = player.participant if participant.version=='N2': player.participant.t1=time.time() return participant.version=='N2' class ClaimN1(Page): form_model = 'player' form_fields = ['claimN1'] @staticmethod def is_displayed(player: Player): participant = player.participant return participant.version=='N1' @staticmethod def before_next_page(player, timeout_happened): player.participant.t1=time.time()-player.participant.t1 class ClaimN2(Page): form_model = 'player' form_fields = ['claimN2'] @staticmethod def is_displayed(player: Player): participant = player.participant return participant.version=='N2' @staticmethod def before_next_page(player, timeout_happened): player.participant.t1=time.time()-player.participant.t1 class ResultsN1(Page): @staticmethod def is_displayed(player: Player): participant = player.participant return participant.version=='N1' class ResultsN2(Page): @staticmethod def is_displayed(player: Player): participant = player.participant return participant.version=='N2' l11=[IntroductionN1,CheckN1,IntroductionN2,CheckN2,Confirmation1,Confirmation2,ClaimN1,ResultsN1,ClaimN2,ResultsN2] page_sequence=l11