from otree.api import * doc = """ Stag_Hunt_Attempt1 """ class C(BaseConstants): NAME_IN_URL = 'coordination_test' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 3 instructions_template = 'coordination_test/instructions.html' PAYOFF_A = cu(75) PAYOFF_B = cu(50) PAYOFF_C = cu(0) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): stag = models.BooleanField( choices=[[True, 'stag'], [False, 'hare']], doc="""This player's decision""", widget=widgets.RadioSelect, ) #FUNCTIONS def set_payoffs(group: Group): for p in group.get_players(): set_payoff(p) def other_player(player: Player): return player.get_others_in_group()[0] def set_payoff(player: Player): payoff_matrix = { (True, True): C.PAYOFF_A, (False, True): C.PAYOFF_B, (False, False): C.PAYOFF_B, (True, False): C.PAYOFF_C, } other = other_player(player) player.payoff = payoff_matrix[(player.stag, other.stag)] # PAGES class instructions(Page): timeout_seconds = 100 class Survey(Page): form_model = 'player' form_fields = ['name', 'age'] class Main(Page): form_model = 'player' form_fields = ['stag'] class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): @staticmethod def vars_for_template(player: Player): opponent = other_player(player) return dict( opponent=opponent, same_choice=player.stag == opponent.stag, my_decision=player.field_display('stag'), opponent_decision=opponent.field_display('stag'), ) page_sequence = [instructions, Main, ResultsWaitPage, Results]