from otree.api import * author = 'Corey Scheinfeld' doc = """ Battle of the Sexes """ class Constants(BaseConstants): name_in_url = 'battle' players_per_group = 2 num_rounds = 5 instructions_template = 'battle/instructions.html' row_role = 'row' column_role = 'column' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): choice = models.BooleanField() partner_choice = models.BooleanField() # FUNCTIONS def creating_session(subsession: Subsession): subsession.group_randomly() def set_payoffs(group: Group): p1 = group.get_player_by_role(Constants.row_role) p2 = group.get_player_by_role(Constants.column_role) p1.partner_choice = p2.choice p2.partner_choice = p1.choice if p1.choice and p2.choice : p1.payoff = 600 p2.payoff = 200 if p1.choice and p2.choice == False: p1.payoff = 0 p2.payoff = 0 if p1.choice == False and p2.choice == False: p1.payoff = 200 p2.payoff = 600 if p1.choice == False and p2.choice : p1.payoff = 0 p2.payoff = 0 # PAGES class Introduction(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Main(Page): form_model = 'player' form_fields = ['choice'] class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): pass page_sequence = [Introduction, Main, ResultsWaitPage, Results]