from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'battle_of_the_sexes' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 80 GAME_ROUNDS = 40 class Subsession(BaseSubsession): pass class Group(BaseGroup): round_number_in_game = models.IntegerField() pairOneChoiceOne = models.BooleanField() pairOneChoiceTwo = models.BooleanField() pairTwoChoiceOne = models.BooleanField() pairTwoChoiceTwo = models.BooleanField() pairOnePayoffOne = models.IntegerField() pairOnePayoffTwo = models.IntegerField() pairTwoPayoffOne = models.IntegerField() pairTwoPayoffTwo = models.IntegerField() def set_payoff(group: Group): session = group.session playerOne, playerTwo, playerThree, playerFour = group.get_players() if group.round_number <= C.GAME_ROUNDS: group.pairOneChoiceOne = playerOne.choice group.pairOneChoiceTwo = playerTwo.choice group.pairTwoChoiceOne = playerThree.choice group.pairTwoChoiceTwo = playerFour.choice choicePairOne = (playerOne.choice, playerTwo.choice) choicePairTwo = (playerThree.choice, playerFour.choice) payoff_matrix = { (True, True): [session.config['game1_payoff_aa1'],session.config['game1_payoff_aa2']], (True, False): [session.config['game1_payoff_ab1'],session.config['game1_payoff_ab2']], (False, True): [session.config['game1_payoff_ba1'],session.config['game1_payoff_ba2']], (False, False): [session.config['game1_payoff_bb1'],session.config['game1_payoff_bb2']] } payoffOne, payoffTwo = payoff_matrix[choicePairOne] payoffThree, payoffFour = payoff_matrix[choicePairTwo] group.pairOnePayoffOne = payoffOne group.pairOnePayoffTwo = payoffTwo group.pairTwoPayoffOne = payoffThree group.pairTwoPayoffTwo = payoffFour else: group.pairOneChoiceOne = playerOne.choice group.pairOneChoiceTwo = playerThree.choice group.pairTwoChoiceOne = playerTwo.choice group.pairTwoChoiceTwo = playerFour.choice choicePairOne = (playerOne.choice, playerThree.choice) choicePairTwo = (playerTwo.choice, playerFour.choice) payoff_matrix = { (True, True): [session.config['game2_payoff_aa1'],session.config['game2_payoff_aa2']], (True, False): [session.config['game2_payoff_ab1'],session.config['game2_payoff_ab2']], (False, True): [session.config['game2_payoff_ba1'],session.config['game2_payoff_ba2']], (False, False): [session.config['game2_payoff_bb1'],session.config['game2_payoff_bb2']] } payoffOne, payoffThree = payoff_matrix[choicePairOne] payoffTwo, payoffFour = payoff_matrix[choicePairTwo] group.pairOnePayoffOne = payoffOne group.pairOnePayoffTwo = payoffThree group.pairTwoPayoffOne = payoffTwo group.pairTwoPayoffTwo = payoffFour playerOne.payoff = payoffOne playerTwo.payoff = payoffTwo playerThree.payoff = payoffThree playerFour.payoff = payoffFour class Player(BasePlayer): choice = models.BooleanField(choices=[[True, 'Choice A'], [False, 'Choice B']], label='What would you like to choose?', widget=widgets.RadioSelect) pretest1 = models.IntegerField(label='What is your payoff if you choose B and your partner chooses B?') pretest2 = models.IntegerField(label="What is your partner's payoff if you choose A and your partner chooses B?") pretest3 = models.IntegerField(label='What is your payoff if you choose A and your partner chooses B?') pretest4 = models.IntegerField(label="What is your partner's payoff if you choose A and your partner chooses A?") pretest5 = models.IntegerField(label='How many rounds are in each match?') pretest6 = models.IntegerField(label='How many matches are you going to play?') pretest7 = models.BooleanField(choices=[[True, 'True'], [False, 'False']], label='True or False: In a match, I play with the same partner throughout our interaction?', widget=widgets.RadioSelect) pretest8 = models.BooleanField(choices=[[True, 'True'], [False, 'False']], label='True or False: In the second match, I play with the same partner that I played in the first match?', widget=widgets.RadioSelect) class Instructions(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def vars_for_template(player: Player): session = player.session return dict( rate=(1 / session.config['real_world_currency_per_point']), participation_fee=int(session.config['participation_fee']), participation_fee_ecus=int(session.config['participation_fee'] / session.config['real_world_currency_per_point']) ) class Pretest(Page): form_model = 'player' form_fields = ['pretest1', 'pretest2', 'pretest3', 'pretest4', 'pretest5', 'pretest6', 'pretest7', 'pretest8'] @staticmethod def is_displayed(player: Player): return player.round_number == 1 class PretestResults(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Play(Page): form_model = 'player' form_fields = ['choice'] @staticmethod def vars_for_template(player: Player): session = player.session group = player.group if player.round_number <= C.GAME_ROUNDS: game_number = 1 game_round_number = player.round_number prev_rounds = group.in_previous_rounds() payoff_matrix = [ [session.config['game1_payoff_aa1'],session.config['game1_payoff_aa2']], [session.config['game1_payoff_ab1'],session.config['game1_payoff_ab2']], [session.config['game1_payoff_ba1'],session.config['game1_payoff_ba2']], [session.config['game1_payoff_bb1'],session.config['game1_payoff_bb2']] ] pairPosition = {1: 1, 2: 2, 3: 3, 4: 4}[player.id_in_group] is_first_player = player.id_in_group == 1 or player.id_in_group == 3 full_info = session.config['game1_full_info'] else: game_number = 2 game_round_number = player.round_number - C.GAME_ROUNDS prev_rounds = group.in_rounds(C.GAME_ROUNDS + 1, player.round_number - 1) payoff_matrix = [ [session.config['game2_payoff_aa1'],session.config['game2_payoff_aa2']], [session.config['game2_payoff_ab1'],session.config['game2_payoff_ab2']], [session.config['game2_payoff_ba1'],session.config['game2_payoff_ba2']], [session.config['game2_payoff_bb1'],session.config['game2_payoff_bb2']] ] pairPosition = {1: 1, 2: 3, 3: 2, 4: 4}[player.id_in_group] is_first_player = player.id_in_group == 1 or player.id_in_group == 2 full_info = session.config['game2_full_info'] group.round_number_in_game = game_round_number return dict( game_number=game_number, game_round_number=game_round_number, aa1=(payoff_matrix[0][0] if is_first_player else payoff_matrix[0][1]), aa2=(payoff_matrix[0][1] if is_first_player else payoff_matrix[0][0]), ab1=(payoff_matrix[1][0] if is_first_player else payoff_matrix[1][1]), ab2=(payoff_matrix[1][1] if is_first_player else payoff_matrix[1][0]), ba1=(payoff_matrix[2][0] if is_first_player else payoff_matrix[2][1]), ba2=(payoff_matrix[2][1] if is_first_player else payoff_matrix[2][0]), bb1=(payoff_matrix[3][0] if is_first_player else payoff_matrix[3][1]), bb2=(payoff_matrix[3][1] if is_first_player else payoff_matrix[3][0]), player=player, pairPosition=pairPosition, prev_rounds=prev_rounds, first_round=(len(prev_rounds) == 0), has_prev_rounds=(len(prev_rounds) > 0), full_info=full_info, isGameOne=(game_number==1) ) class PlayWaitPage(WaitPage): after_all_players_arrive = set_payoff class Results(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == C.NUM_ROUNDS @staticmethod def vars_for_template(player: Player): session = player.session group = player.group participant = player.participant participant.payoff = cu(round(participant.payoff * session.config['real_world_currency_per_point']) / session.config['real_world_currency_per_point']) return dict( payoff=participant.payoff_plus_participation_fee(), pn=player.id_in_group ) page_sequence = [Instructions, Pretest, PretestResults, Play, PlayWaitPage, Results]