from otree.api import * author = 'Corey Scheinfeld' doc = """ Hawk-Dove Game """ class Constants(BaseConstants): name_in_url = 'hawk_dove' players_per_group = 2 num_rounds = 5 instructions_template = 'hawk_dove/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): is_dove = models.BooleanField(choices=[[True, 'Dove'], [False, 'Hawk']]) # FUNCTIONS def set_payoffs(group: Group): group = group.get_players() p1 = group[0] p2 = group[1] choices = [p1.is_dove, p2.is_dove] if choices == [True, True]: p1.payoff = 1.5 p2.payoff = 1.5 if choices == [True, False]: p1.payoff = 0 p2.payoff = 3 if choices == [False, False]: p1.payoff = -1 p2.payoff = -1 if choices == [False, True]: p1.payoff = 0 p2.payoff = 3 # PAGES class Introduction(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Main(Page): form_model = 'player' form_fields = ['is_dove'] class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): @staticmethod def vars_for_template(player: Player): return dict(partner=player.get_others_in_group()[0]) page_sequence = [Introduction, Main, ResultsWaitPage, Results]