from otree.api import * import random doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'social_learning_star' PLAYERS_PER_GROUP = 5 NUM_ROUNDS = 80 quiz_correct = 1 quiz_bonus = 1 guess_correct = 5 belief_payment = 2 participant_fee = 8 male_link = [['https://i.imgur.com/cKIK5BW.png', 'Adam'], ['https://i.imgur.com/ANNCedm.png', 'Ben'], ['https://i.imgur.com/RpiKCuq.png', 'Charles'], ['https://i.imgur.com/Yf17Sdv.png', 'Daniel'], ['https://i.imgur.com/wKTO2pm.png', 'Edward'], ['https://i.imgur.com/mABiM5L.png', 'George'], ['https://i.imgur.com/BL7Vp8G.png', 'Henry'], ['https://i.imgur.com/emkx6dl.png', 'John'], ['https://i.imgur.com/iWfKsiq.png', 'Martin'], ['https://i.imgur.com/8nIOJfG.png', 'Tom'] ] female_link = [['https://i.imgur.com/mcnlsDa.png', 'Anne'], ['https://i.imgur.com/hQTTOPT.png', 'Barbara'], ['https://i.imgur.com/0eHjDYg.png', 'Caroline'], ['https://i.imgur.com/yjk25hp.png', 'Diana'], ['https://i.imgur.com/9571b0a.png', 'Emily'], ['https://i.imgur.com/oiFiWsE.png', 'Gabrielle'], ['https://i.imgur.com/uBZFySm.png', 'Hannah'], ['https://i.imgur.com/c6aK2zc.png', 'Jacqueline'], ['https://i.imgur.com/spsAHl1.png', 'Mary'], ['https://i.imgur.com/A3CwzJg.png', 'Tracy'] ] link = [['https://i.imgur.com/mcnlsDa.png', 'Anne'], ['https://i.imgur.com/hQTTOPT.png', 'Barbara'], ['https://i.imgur.com/0eHjDYg.png', 'Caroline'], ['https://i.imgur.com/yjk25hp.png', 'Diana'], ['https://i.imgur.com/9571b0a.png', 'Emily'], ['https://i.imgur.com/oiFiWsE.png', 'Gabrielle'], ['https://i.imgur.com/uBZFySm.png', 'Hannah'], ['https://i.imgur.com/c6aK2zc.png', 'Jacqueline'], ['https://i.imgur.com/spsAHl1.png', 'Mary'], ['https://i.imgur.com/A3CwzJg.png', 'Tracy'], ['https://i.imgur.com/cKIK5BW.png', 'Adam'], ['https://i.imgur.com/ANNCedm.png', 'Ben'], ['https://i.imgur.com/RpiKCuq.png', 'Charles'], ['https://i.imgur.com/Yf17Sdv.png', 'Daniel'], ['https://i.imgur.com/wKTO2pm.png', 'Edward'], ['https://i.imgur.com/mABiM5L.png', 'George'], ['https://i.imgur.com/BL7Vp8G.png', 'Henry'], ['https://i.imgur.com/emkx6dl.png', 'John'], ['https://i.imgur.com/iWfKsiq.png', 'Martin'], ['https://i.imgur.com/8nIOJfG.png', 'Tom'] ] q1 = 'Which Dickens character asked for more?' q2 = 'What city provides the setting for The Phantom of the Opera?' q3 = 'What tennis player was listed as the world’s highest‐earning female athlete at the start of 2006?' q4 = 'What Jack Nicholson movie was hyped: “Brace yourself for Melvin”?' q5 = 'What decade provides the setting for the 2005 movie King Kong?' q6 = 'What was The Police’s best-selling single?' q7 = 'Which of the following actions would be the most effective in decreasing acid rain and acid deposition problems?' q8 = 'In general, which of the following is the best long‐term method of preventing Extinctions?' q9 = 'The ultimate source of energy for terrestrial ecosystems is' q10 = 'All of the following are true of the movement to prohibit alcoholic beverages in the United States EXCEPT:' q11 = 'What’s the Shakespeare play if “All the world’s a stage”?' q12 = 'What war do the girls in Little Women grow up during?' q13 = 'The encomienda system in the Spanish Empire in the Americas most closely resembled the European practice of' q14 = 'Who steers the shell and motivates the rowers in a crew race?' q15 = 'What kind of animals starred in the movie Happy Feet?' q16 = 'Of the following, which is the most serious immediate problem associated with sanitary landfills?' c1 = 'Oliver Twist' c2 = 'Paris' c3 = 'Maria Sharapova' c4 = 'As Good As It Gets' c5 = '1930s' c6 = 'Every Breath You Take' c7 = 'Reducing use of fossil fuels' c8 = 'Protecting the habitats of endangered species' c9 = 'the Sun' c10 = 'It arose quite suddenly amid the hysteria surrounding the First World War.' c11 = 'As You Like It' c12 = 'Civil War' c13 = 'manorialism' c14 = 'Coxswain' c15 = 'Penguins' c16 = 'Leachate contamination of groundwater' n = 'None of the above' class Subsession(BaseSubsession): random1 = models.IntegerField() random2 = models.IntegerField() random3 = models.IntegerField() random4 = models.IntegerField() random5 = models.IntegerField() random6 = models.IntegerField() random7 = models.IntegerField() random8 = models.IntegerField() random9 = models.IntegerField() random10 = models.IntegerField() random11 = models.IntegerField() random12 = models.IntegerField() random13 = models.IntegerField() random14 = models.IntegerField() random15 = models.IntegerField() random16 = models.IntegerField() class Group(BaseGroup): center = models.IntegerField() class Player(BasePlayer): question1 = models.StringField( widget=widgets.RadioSelect, label=C.q1 ) question2 = models.StringField( widget=widgets.RadioSelect, label=C.q2 ) question3 = models.StringField( widget=widgets.RadioSelect, label=C.q3 ) question4 = models.StringField( widget=widgets.RadioSelect, label=C.q4 ) question5 = models.StringField( widget=widgets.RadioSelect, label=C.q5 ) question6 = models.StringField( widget=widgets.RadioSelect, label=C.q6 ) question7 = models.StringField( widget=widgets.RadioSelect, label=C.q7 ) question8 = models.StringField( widget=widgets.RadioSelect, label=C.q8 ) question9 = models.StringField( widget=widgets.RadioSelect, label=C.q9 ) question10 = models.StringField( widget=widgets.RadioSelect, label=C.q10 ) question11 = models.StringField( widget=widgets.RadioSelect, label=C.q11 ) question12 = models.StringField( widget=widgets.RadioSelect, label=C.q12 ) question13 = models.StringField( widget=widgets.RadioSelect, label=C.q13 ) question14 = models.StringField( widget=widgets.RadioSelect, label=C.q14 ) question15 = models.StringField( widget=widgets.RadioSelect, label=C.q15 ) question16 = models.StringField( widget=widgets.RadioSelect, label=C.q16 ) state1 = models.IntegerField() state2 = models.IntegerField() state3 = models.IntegerField() state4 = models.IntegerField() state5 = models.IntegerField() state6 = models.IntegerField() state7 = models.IntegerField() state8 = models.IntegerField() state9 = models.IntegerField() state10 = models.IntegerField() state11 = models.IntegerField() state12 = models.IntegerField() state13 = models.IntegerField() state14 = models.IntegerField() state15 = models.IntegerField() state16 = models.IntegerField() state_trivia = models.IntegerField() correct1 = models.IntegerField() correct2 = models.IntegerField() correct3 = models.IntegerField() correct4 = models.IntegerField() correct5 = models.IntegerField() correct6 = models.IntegerField() correct7 = models.IntegerField() correct8 = models.IntegerField() correct9 = models.IntegerField() correct10 = models.IntegerField() correct11 = models.IntegerField() correct12 = models.IntegerField() correct13 = models.IntegerField() correct14 = models.IntegerField() correct15 = models.IntegerField() correct16 = models.IntegerField() center = models.BooleanField() correct = models.IntegerField() initial_e = models.IntegerField( choices=[0, 1, 2, 3, 4] ) answer_e = models.IntegerField( choices=[0, 1, 2, 3, 4] ) correct_e = models.FloatField(min=0, max=100) neighbor1 = models.IntegerField() neighbor2 = models.IntegerField() neighbor3 = models.IntegerField() neighbor4 = models.IntegerField() neighbor = models.IntegerField() neighbor1_belief = models.IntegerField() neighbor2_belief = models.IntegerField() neighbor3_belief = models.IntegerField() neighbor4_belief = models.IntegerField() neighbor_belief = models.IntegerField() previous_belief = models.IntegerField() neighbor1_correct = models.FloatField(min=0, max=100) neighbor2_correct = models.FloatField(min=0, max=100) neighbor3_correct = models.FloatField(min=0, max=100) neighbor4_correct = models.FloatField(min=0, max=100) neighbor_correct = models.FloatField(min=0, max=100) guess_payoff = models.FloatField() quiz_payoff = models.FloatField() belief_payoff = models.FloatField() # functions def set_random(subsession: Subsession): if subsession.round_number == 1: subsession.random1 = random.randint(0, 4) subsession.random2 = random.randint(0, 4) subsession.random3 = random.randint(0, 4) subsession.random4 = random.randint(0, 4) elif subsession.round_number == 21: subsession.random5 = random.randint(0, 4) subsession.random6 = random.randint(0, 4) subsession.random7 = random.randint(0, 4) subsession.random8 = random.randint(0, 4) elif subsession.round_number == 41: subsession.random9 = random.randint(0, 4) subsession.random10 = random.randint(0, 4) subsession.random11 = random.randint(0, 4) subsession.random12 = random.randint(0, 4) elif subsession.round_number == 61: subsession.random13 = random.randint(0, 4) subsession.random14 = random.randint(0, 4) subsession.random15 = random.randint(0, 4) subsession.random16 = random.randint(0, 4) def set_state(subsession: Subsession): list1 = [] list2 = [] if subsession.session.random_gender == 0: if subsession.round_number == 1: groups = subsession.get_groups() group1 = groups[0] group2 = groups[1] for player in group1.get_players(): list1.append(player.id_in_group) group1.center = random.choice(list1) for player in group2.get_players(): list2.append(player.id_in_group) group2.center = random.choice(list2) elif subsession.round_number == 21: groups = subsession.get_groups() group1 = groups[0] group2 = groups[1] for player in group1.get_players(): if not player.in_round(1).center: list1.append(player.id_in_group) group1.center = random.choice(list1) for player in group2.get_players(): if not player.in_round(1).center: list2.append(player.id_in_group) group2.center = random.choice(list2) elif subsession.round_number == 41: groups = subsession.get_groups() group1 = groups[0] group2 = groups[1] for player in group1.get_players(): if not player.in_round(1).center and not player.in_round(21).center and player.participant.gender == 'Female': list1.append(player.id_in_group) group1.center = random.choice(list1) for player in group2.get_players(): if not player.in_round(1).center and not player.in_round(21).center and player.participant.gender == 'Male': list2.append(player.id_in_group) group2.center = random.choice(list2) elif subsession.round_number == 61: groups = subsession.get_groups() group1 = groups[0] group2 = groups[1] for player in group1.get_players(): if not player.in_round(1).center and not player.in_round(21).center and not player.in_round(41).center and player.participant.gender == 'Female': list1.append(player.id_in_group) group1.center = random.choice(list1) for player in group2.get_players(): if not player.in_round(1).center and not player.in_round(21).center and not player.in_round(41).center and player.participant.gender == 'Male': list2.append(player.id_in_group) group2.center = random.choice(list2) else: if subsession.round_number == 1: groups = subsession.get_groups() group1 = groups[0] group2 = groups[1] for player in group1.get_players(): if player.participant.gender == 'Female': list1.append(player.id_in_group) group1.center = random.choice(list1) for player in group2.get_players(): if player.participant.gender == 'Male': list2.append(player.id_in_group) group2.center = random.choice(list2) elif subsession.round_number == 21: groups = subsession.get_groups() group1 = groups[0] group2 = groups[1] for player in group1.get_players(): if not player.in_round(1).center and player.participant.gender == 'Female': list1.append(player.id_in_group) group1.center = random.choice(list1) for player in group2.get_players(): if not player.in_round(1).center and player.participant.gender == 'Male': list2.append(player.id_in_group) group2.center = random.choice(list2) elif subsession.round_number == 41: groups = subsession.get_groups() group1 = groups[0] group2 = groups[1] for player in group1.get_players(): if not player.in_round(1).center and not player.in_round(21).center: list1.append(player.id_in_group) group1.center = random.choice(list1) for player in group2.get_players(): if not player.in_round(1).center and not player.in_round(21).center: list2.append(player.id_in_group) group2.center = random.choice(list2) elif subsession.round_number == 61: groups = subsession.get_groups() group1 = groups[0] group2 = groups[1] for player in group1.get_players(): if not player.in_round(1).center and not player.in_round(21).center and not player.in_round(41).center: list1.append(player.id_in_group) group1.center = random.choice(list1) for player in group2.get_players(): if not player.in_round(1).center and not player.in_round(21).center and not player.in_round(41).center: list2.append(player.id_in_group) group2.center = random.choice(list2) for player in subsession.get_players(): if player.id_in_group == player.group.center: player.center = True player.neighbor1 = player.get_others_in_group()[0].id_in_group player.neighbor2 = player.get_others_in_group()[1].id_in_group player.neighbor3 = player.get_others_in_group()[2].id_in_group player.neighbor4 = player.get_others_in_group()[3].id_in_group else: player.center = False player.neighbor = player.group.center if subsession.round_number == 1: for p in subsession.get_players(): p.state_trivia = p.state1 + p.state2 + p.state3 + p.state4 if p.state1 == 0 and p.question1 == C.c1: p.correct1 = 1 elif p.state1 == 1 and p.question1 == C.n: p.correct1 = 1 else: p.correct1 = 0 if p.state2 == 0 and p.question2 == C.c2: p.correct2 = 1 elif p.state2 == 1 and p.question2 == C.n: p.correct2 = 1 else: p.correct2 = 0 if p.state3 == 0 and p.question3 == C.c3: p.correct3 = 1 elif p.state3 == 1 and p.question3 == C.n: p.correct3 = 1 else: p.correct3 = 0 if p.state4 == 0 and p.question4 == C.c4: p.correct4 = 1 elif p.state4 == 1 and p.question4 == C.n: p.correct4 = 1 else: p.correct4 = 0 p.correct = p.correct1 + p.correct2 + p.correct3 + p.correct4 return p.state_trivia, p.correct1, p.correct2, p.correct3, p.correct4, p.correct elif subsession.round_number == 21: for p in subsession.get_players(): p.state_trivia = p.state5 + p.state6 + p.state7 + p.state8 if p.state5 == 0 and p.question5 == C.c5: p.correct5 = 1 elif p.state5 == 1 and p.question5 == C.n: p.correct5 = 1 else: p.correct5 = 0 if p.state6 == 0 and p.question6 == C.c6: p.correct6 = 1 elif p.state6 == 1 and p.question6 == C.n: p.correct6 = 1 else: p.correct6 = 0 if p.state7 == 0 and p.question7 == C.c7: p.correct7 = 1 elif p.state7 == 1 and p.question7 == C.n: p.correct7 = 1 else: p.correct7 = 0 if p.state8 == 0 and p.question8 == C.c8: p.correct8 = 1 elif p.state8 == 1 and p.question8 == C.n: p.correct8 = 1 else: p.correct8 = 0 p.correct = p.correct5 + p.correct6 + p.correct7 + p.correct8 return p.state_trivia, p.correct5, p.correct6, p.correct7, p.correct8, p.correct elif subsession.round_number == 41: for p in subsession.get_players(): p.state_trivia = p.state9 + p.state10 + p.state11 + p.state12 if p.state9 == 0 and p.question9 == C.c9: p.correct9 = 1 elif p.state9 == 1 and p.question9 == C.n: p.correct9 = 1 else: p.correct9 = 0 if p.state10 == 0 and p.question10 == C.c10: p.correct10 = 1 elif p.state10 == 1 and p.question10 == C.n: p.correct10 = 1 else: p.correct10 = 0 if p.state11 == 0 and p.question11 == C.c11: p.correct11 = 1 elif p.state11 == 1 and p.question11 == C.n: p.correct11 = 1 else: p.correct11 = 0 if p.state12 == 0 and p.question12 == C.c12: p.correct12 = 1 elif p.state12 == 1 and p.question12 == C.n: p.correct12 = 1 else: p.correct12 = 0 p.correct = p.correct9 + p.correct10 + p.correct11 + p.correct12 return p.state_trivia, p.correct9, p.correct10, p.correct11, p.correct12, p.correct elif subsession.round_number == 61: for p in subsession.get_players(): p.state_trivia = p.state13 + p.state14 + p.state15 + p.state16 if p.state13 == 0 and p.question13 == C.c13: p.correct13 = 1 elif p.state13 == 1 and p.question13 == C.n: p.correct13 = 1 else: p.correct13 = 0 if p.state14 == 0 and p.question14 == C.c14: p.correct14 = 1 elif p.state14 == 1 and p.question14 == C.n: p.correct14 = 1 else: p.correct14 = 0 if p.state15 == 0 and p.question15 == C.c15: p.correct15 = 1 elif p.state15 == 1 and p.question15 == C.n: p.correct15 = 1 else: p.correct15 = 0 if p.state16 == 0 and p.question16 == C.c16: p.correct16 = 1 elif p.state16 == 1 and p.question16 == C.n: p.correct16 = 1 else: p.correct16 = 0 p.correct = p.correct13 + p.correct14 + p.correct15 + p.correct16 return p.state_trivia, p.correct13, p.correct14, p.correct15, p.correct16, p.correct return player.neighbor1, player.neighbor2, player.neighbor3, player.neighbor4, player.neighbor def get_quiz(subsession: Subsession): if 1 < subsession.round_number <= 20: for p in subsession.get_players(): p.center = p.in_round(1).center p.question1 = p.in_round(1).question1 p.question2 = p.in_round(1).question2 p.question3 = p.in_round(1).question3 p.question4 = p.in_round(1).question4 if p.in_round(1).center: p.neighbor1 = p.in_round(1).neighbor1 p.neighbor2 = p.in_round(1).neighbor2 p.neighbor3 = p.in_round(1).neighbor3 p.neighbor4 = p.in_round(1).neighbor4 else: p.neighbor = p.in_round(1).neighbor elif 21 < subsession.round_number <= 40: for p in subsession.get_players(): p.center = p.in_round(21).center p.question5 = p.in_round(21).question5 p.question6 = p.in_round(21).question6 p.question7 = p.in_round(21).question7 p.question8 = p.in_round(21).question8 if p.in_round(21).center: p.neighbor1 = p.in_round(21).neighbor1 p.neighbor2 = p.in_round(21).neighbor2 p.neighbor3 = p.in_round(21).neighbor3 p.neighbor4 = p.in_round(21).neighbor4 else: p.neighbor = p.in_round(21).neighbor elif 41 < subsession.round_number <= 60: for p in subsession.get_players(): p.center = p.in_round(41).center p.question9 = p.in_round(41).question9 p.question10 = p.in_round(41).question10 p.question11 = p.in_round(41).question11 p.question12 = p.in_round(41).question12 if p.in_round(41).center: p.neighbor1 = p.in_round(41).neighbor1 p.neighbor2 = p.in_round(41).neighbor2 p.neighbor3 = p.in_round(41).neighbor3 p.neighbor4 = p.in_round(41).neighbor4 else: p.neighbor = p.in_round(41).neighbor elif 61 < subsession.round_number <= 80: for p in subsession.get_players(): p.center = p.in_round(61).center p.question13 = p.in_round(61).question13 p.question14 = p.in_round(61).question14 p.question15 = p.in_round(61).question15 p.question16 = p.in_round(61).question16 if p.in_round(61).center: p.neighbor1 = p.in_round(61).neighbor1 p.neighbor2 = p.in_round(61).neighbor2 p.neighbor3 = p.in_round(61).neighbor3 p.neighbor4 = p.in_round(61).neighbor4 else: p.neighbor = p.in_round(61).neighbor def get_belief(subsession: Subsession): if subsession.round_number in [1, 21, 41, 61]: for player in subsession.get_players(): player.previous_belief = player.initial_e if player.center: n1 = player.group.get_player_by_id(player.neighbor1) n2 = player.group.get_player_by_id(player.neighbor2) n3 = player.group.get_player_by_id(player.neighbor3) n4 = player.group.get_player_by_id(player.neighbor4) player.neighbor1_belief = n1.initial_e player.neighbor2_belief = n2.initial_e player.neighbor3_belief = n3.initial_e player.neighbor4_belief = n4.initial_e else: n = player.group.get_player_by_id(player.neighbor) player.neighbor_belief = n.initial_e else: for player in subsession.get_players(): player.previous_belief = player.in_round(subsession.round_number-1).answer_e if player.center: n1 = player.group.get_player_by_id(player.neighbor1) n2 = player.group.get_player_by_id(player.neighbor2) n3 = player.group.get_player_by_id(player.neighbor3) n4 = player.group.get_player_by_id(player.neighbor4) player.neighbor1_belief = n1.in_round(subsession.round_number-1).answer_e player.neighbor2_belief = n2.in_round(subsession.round_number-1).answer_e player.neighbor3_belief = n3.in_round(subsession.round_number-1).answer_e player.neighbor4_belief = n4.in_round(subsession.round_number-1).answer_e else: n = player.group.get_player_by_id(player.neighbor) player.neighbor_belief = n.in_round(subsession.round_number-1).answer_e def set_payoff(subsession: Subsession): paying_quiz = random.choice([1, 21, 41, 61]) subsession.session.paying_quiz = paying_quiz paying_guess = paying_quiz + 19 belief1 = paying_quiz + 4 belief2 = paying_quiz + 9 belief3 = paying_quiz + 14 belief4 = paying_quiz + 19 i = random.random() * 100 j = random.random() * 100 k = random.randint(1, 4) l = random.randint(1, 4) for p in subsession.get_players(): if p.in_round(paying_quiz).correct == 4: p.quiz_payoff = 4 * C.quiz_correct + C.quiz_bonus else: p.quiz_payoff = p.in_round(paying_quiz).correct * C.quiz_correct if p.in_round(paying_guess).answer_e == p.in_round(paying_quiz).state_trivia: p.guess_payoff = C.guess_correct else: p.guess_payoff = 0 if k == 1: if not p.in_round(paying_quiz).center: if p.in_round(belief1).neighbor_correct >= i: if p.in_round(belief1).neighbor_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if l == 1: if p.in_round(belief1).neighbor1_correct >= i: if p.in_round(belief1).neighbor1_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 elif l == 2: if p.in_round(belief1).neighbor2_correct >= i: if p.in_round(belief1).neighbor2_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 elif l == 3: if p.in_round(belief1).neighbor3_correct >= i: if p.in_round(belief1).neighbor3_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if p.in_round(belief1).neighbor4_correct >= i: if p.in_round(belief1).neighbor4_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 elif k == 2: if not p.in_round(paying_quiz).center: if p.in_round(belief2).neighbor_correct >= i: if p.in_round(belief2).neighbor_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if l == 1: if p.in_round(belief2).neighbor1_correct >= i: if p.in_round(belief2).neighbor1_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 elif l == 2: if p.in_round(belief2).neighbor2_correct >= i: if p.in_round(belief2).neighbor2_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 elif l == 3: if p.in_round(belief2).neighbor3_correct >= i: if p.in_round(belief2).neighbor3_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if p.in_round(belief2).neighbor4_correct >= i: if p.in_round(belief2).neighbor4_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 elif k == 3: if not p.in_round(paying_quiz).center: if p.in_round(belief3).neighbor_correct >= i: if p.in_round(belief3).neighbor_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if l == 1: if p.in_round(belief3).neighbor1_correct >= i: if p.in_round(belief3).neighbor1_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 elif l == 2: if p.in_round(belief3).neighbor2_correct >= i: if p.in_round(belief3).neighbor2_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 elif l == 3: if p.in_round(belief3).neighbor3_correct >= i: if p.in_round(belief3).neighbor3_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if p.in_round(belief3).neighbor4_correct >= i: if p.in_round(belief3).neighbor4_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if not p.in_round(paying_quiz).center: if p.in_round(belief4).neighbor_correct >= i: if p.in_round(belief4).neighbor_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if l == 1: if p.in_round(belief4).neighbor1_correct >= i: if p.in_round(belief4).neighbor1_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 elif l == 2: if p.in_round(belief4).neighbor2_correct >= i: if p.in_round(belief4).neighbor2_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 elif l == 3: if p.in_round(belief4).neighbor3_correct >= i: if p.in_round(belief4).neighbor3_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if p.in_round(belief4).neighbor4_correct >= i: if p.in_round(belief4).neighbor4_belief == p.in_round(paying_quiz).state_trivia: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 else: if j < i: p.belief_payoff = C.belief_payment else: p.belief_payoff = 0 p.payoff = p.quiz_payoff + p.guess_payoff + p.belief_payoff + C.participant_fee return p.quiz_payoff, p.guess_payoff, p.belief_payoff, p.payoff def question1_choices(player): given_choices = ['The Artful Dodger', 'Tiny Tim', 'Miss Havisham', 'Nicholas Nickleby', 'Oliver Twist'] choices = given_choices[0:player.subsession.random1] + given_choices[player.subsession.random1+1:] + [C.n] correct_answer = C.c1 if correct_answer in choices: player.state1 = 0 else: player.state1 = 1 return choices def question2_choices(player): given_choices = ['London', 'New York', 'Paris', 'Rome', 'Venice'] choices = given_choices[0:player.subsession.random2] + given_choices[player.subsession.random2+1:] + [C.n] correct_answer = C.c2 if correct_answer in choices: player.state2 = 0 else: player.state2 = 1 return choices def question3_choices(player): given_choices = ['Anna Kournikova', 'Serena Williams', 'Maria Sharapova', 'Venus Williams', 'Lindsay Davenport'] choices = given_choices[0:player.subsession.random3] + given_choices[player.subsession.random3+1:] + [C.n] correct_answer = C.c3 if correct_answer in choices: player.state3 = 0 else: player.state3 = 1 return choices def question4_choices(player): given_choices = ['One Flew Over the Cuckoo’s Nest', 'As Good As It Gets', 'The Shining', 'Five Easy Pieces', 'About Schmidt'] choices = given_choices[0:player.subsession.random4] + given_choices[player.subsession.random4+1:] + [C.n] correct_answer = C.c4 if correct_answer in choices: player.state4 = 0 else: player.state4 = 1 return choices def question5_choices(player): given_choices = ['1910s', '1920s', '1930s', '1940s', '1950s'] choices = given_choices[0:player.subsession.random5] + given_choices[player.subsession.random5+1:] + [C.n] correct_answer = C.c5 if correct_answer in choices: player.state5 = 0 else: player.state5 = 1 return choices def question6_choices(player): given_choices = ['Every Little Thing She Does Is Magic', 'Roxanne', 'Don’t Stand So Close to Me', 'Every Breath You Take', 'I Want to Know What Love Is'] choices = given_choices[0:player.subsession.random6] + given_choices[player.subsession.random6+1:] + [C.n] correct_answer = C.c6 if correct_answer in choices: player.state6 = 0 else: player.state6 = 1 return choices def question7_choices(player): given_choices = ['Using higher smokestacks', 'Developing acid‐resistant crops', 'Adding lime to acidified lakes', 'Relocating power plants to areas of lower population density', 'Reducing use of fossil fuels'] choices = given_choices[0:player.subsession.random7] + given_choices[player.subsession.random7+1:] + [C.n] correct_answer = C.c7 if correct_answer in choices: player.state7 = 0 else: player.state7 = 1 return choices def question8_choices(player): given_choices = ['Breeding endangered species in captivity', 'Protecting the habitats of endangered species', 'Paying people not to kill endangered species', 'Providing food to endangered species in the wild', 'Removing predators from areas that contain endangered species'] choices = given_choices[0:player.subsession.random8] + given_choices[player.subsession.random8+1:] + [C.n] correct_answer = C.c8 if correct_answer in choices: player.state8 = 0 else: player.state8 = 1 return choices def question9_choices(player): given_choices = ['nutrients in soil', 'nutrients in vegetation', 'primary consumers', 'producers', 'the Sun'] choices = given_choices[0:player.subsession.random9] + given_choices[player.subsession.random9+1:] + [C.n] correct_answer = C.c9 if correct_answer in choices: player.state9 = 0 else: player.state9 = 1 return choices def question10_choices(player): given_choices = ['It arose quite suddenly amid the hysteria surrounding the First World War.', 'It won the support of many progressive reformers.', 'It was often favored by people who disliked immigrants and their cultural practices.', 'It was a movement in which women played leading roles.', 'It gained strength from new scientific evidence that alcohol was harmful to health.'] choices = given_choices[0:player.subsession.random10] + given_choices[player.subsession.random10+1:] + [C.n] correct_answer = C.c10 if correct_answer in choices: player.state10 = 0 else: player.state10 = 1 return choices def question11_choices(player): given_choices = ['Hamlet', 'Romeo and Juliet', 'A Midsummer Night’s Dream', 'Much Ado About Nothing', 'As You Like It'] choices = given_choices[0:player.subsession.random11] + given_choices[player.subsession.random11+1:] + [C.n] correct_answer = C.c11 if correct_answer in choices: player.state11 = 0 else: player.state11 = 1 return choices def question12_choices(player): given_choices = ['American Revolution', 'World War I', 'World War II', 'Civil War', 'Vietnam War'] choices = given_choices[0:player.subsession.random12] + given_choices[player.subsession.random12+1:] + [C.n] correct_answer = C.c12 if correct_answer in choices: player.state12 = 0 else: player.state12 = 1 return choices def question13_choices(player): given_choices = ['absolutism', 'primogeniture', 'patronage', 'manorialism', 'nepotism'] choices = given_choices[0:player.subsession.random13] + given_choices[player.subsession.random13+1:] + [C.n] correct_answer = C.c13 if correct_answer in choices: player.state13 = 0 else: player.state13 = 1 return choices def question14_choices(player): given_choices = ['Coxswain', 'Sculler', 'Sweep', 'Rigger', 'Stern'] choices = given_choices[0:player.subsession.random14] + given_choices[player.subsession.random14+1:] + [C.n] correct_answer = C.c14 if correct_answer in choices: player.state14 = 0 else: player.state14 = 1 return choices def question15_choices(player): given_choices = ['Elephants', 'Chickens', 'Monkeys', 'Penguins', 'Rabbits'] choices = given_choices[0:player.subsession.random15] + given_choices[player.subsession.random15+1:] + [C.n] correct_answer = C.c15 if correct_answer in choices: player.state15 = 0 else: player.state15 = 1 return choices def question16_choices(player): given_choices = ['Generation of CO2 gas', 'Leachate contamination of groundwater', 'Release of disease organisms', 'Incomplete degradation of wastes', 'Compaction and settling'] choices = given_choices[0:player.subsession.random16] + given_choices[player.subsession.random16+1:] + [C.n] correct_answer = C.c16 if correct_answer in choices: player.state16 = 0 else: player.state16 = 1 return choices #page class ShuffleWaitPage(WaitPage): wait_for_all_groups = True @staticmethod def after_all_players_arrive(subsession): male_matrix = [] male_matrix_never_center = [] male_matrix_ever_center = [] female_matrix = [] female_matrix_never_center = [] female_matrix_ever_center = [] players = subsession.get_players() for player in players: if player.participant.gender == 'Female': female_matrix.append(player.id_in_subsession) else: male_matrix.append(player.id_in_subsession) if subsession.session.random_gender == 0: if subsession.round_number == 1 or subsession.round_number == 21: shuffle_male = random.sample(male_matrix, len(male_matrix)) shuffle_female = random.sample(female_matrix, len(female_matrix)) matrix = [shuffle_male, shuffle_female] subsession.set_group_matrix(matrix) elif 1 < subsession.round_number <= 20: subsession.group_like_round(1) elif 21 < subsession.round_number <= 40: subsession.group_like_round(21) elif subsession.round_number == 41: for player in players: if player.in_round(1).center or player.in_round(21).center: if player.participant.gender == 'Female': female_matrix_ever_center.append(player.id_in_subsession) else: male_matrix_ever_center.append(player.id_in_subsession) else: if player.participant.gender == 'Female': female_matrix_never_center.append(player.id_in_subsession) else: male_matrix_never_center.append(player.id_in_subsession) new_center_1 = random.sample(female_matrix_never_center, 1) new_center_2 = random.sample(male_matrix_never_center, 1) female_matrix.remove(new_center_1[0]) male_matrix.remove(new_center_2[0]) shuffle_male = random.sample(male_matrix, len(male_matrix)) shuffle_female = random.sample(female_matrix, len(female_matrix)) matrix_1 = shuffle_male[0:2] + shuffle_female[0:2] + new_center_1 matrix_2 = shuffle_male[2:] + shuffle_female[2:] + new_center_2 shuffle_1 = random.sample(matrix_1, len(matrix_1)) shuffle_2 = random.sample(matrix_2, len(matrix_2)) matrix = [shuffle_1, shuffle_2] subsession.set_group_matrix(matrix) elif subsession.round_number == 61: for player in players: if player.in_round(1).center or player.in_round(21).center or player.in_round(41).center: if player.participant.gender == 'Female': female_matrix_ever_center.append(player.id_in_subsession) else: male_matrix_ever_center.append(player.id_in_subsession) else: if player.participant.gender == 'Female': female_matrix_never_center.append(player.id_in_subsession) else: male_matrix_never_center.append(player.id_in_subsession) new_center_1 = random.sample(female_matrix_never_center, 1) new_center_2 = random.sample(male_matrix_never_center, 1) female_matrix.remove(new_center_1[0]) male_matrix.remove(new_center_2[0]) shuffle_male = random.sample(male_matrix, len(male_matrix)) shuffle_female = random.sample(female_matrix, len(female_matrix)) matrix_1 = shuffle_male[0:2] + shuffle_female[0:2] + new_center_1 matrix_2 = shuffle_male[2:] + shuffle_female[2:] + new_center_2 shuffle_1 = random.sample(matrix_1, len(matrix_1)) shuffle_2 = random.sample(matrix_2, len(matrix_2)) matrix = [shuffle_1, shuffle_2] subsession.set_group_matrix(matrix) elif 41 < subsession.round_number <= 60: subsession.group_like_round(41) elif 61 < subsession.round_number <= 80: subsession.group_like_round(61) else: if subsession.round_number == 1 or subsession.round_number == 21: shuffle_male = random.sample(male_matrix, len(male_matrix)) shuffle_female = random.sample(female_matrix, len(female_matrix)) matrix_1 = shuffle_male[0:2] + shuffle_female[0:3] matrix_2 = shuffle_male[2:] + shuffle_female[3:] shuffle_1 = random.sample(matrix_1, len(matrix_1)) shuffle_2 = random.sample(matrix_2, len(matrix_2)) matrix = [shuffle_1, shuffle_2] subsession.set_group_matrix(matrix) elif 1 < subsession.round_number <= 20: subsession.group_like_round(1) elif 21 < subsession.round_number <= 40: subsession.group_like_round(21) elif subsession.round_number == 41 or subsession.round_number == 61: shuffle_male = random.sample(male_matrix, len(male_matrix)) shuffle_female = random.sample(female_matrix, len(female_matrix)) matrix = [shuffle_male, shuffle_female] subsession.set_group_matrix(matrix) elif 41 < subsession.round_number <= 60: subsession.group_like_round(41) elif 61 < subsession.round_number <= 80: subsession.group_like_round(61) class InstructionTrivia(Page): def is_displayed(self): display = [1, 21, 41, 61] return self.round_number in display class WaitRandom(WaitPage): wait_for_all_groups = True after_all_players_arrive = 'set_random' def is_displayed(self): display = [1, 21, 41, 61] return self.round_number in display class Trivia1(Page): form_model = 'player' form_fields = ['question1', 'question2', 'question3', 'question4'] def is_displayed(self): return self.round_number == 1 class Trivia2(Page): form_model = 'player' form_fields = ['question5', 'question6', 'question7', 'question8'] def is_displayed(self): return self.round_number == 21 class Trivia3(Page): form_model = 'player' form_fields = ['question9', 'question10', 'question11', 'question12'] def is_displayed(self): return self.round_number == 41 class Trivia4(Page): form_model = 'player' form_fields = ['question13', 'question14', 'question15', 'question16'] def is_displayed(self): return self.round_number == 61 class WaitQuiz(WaitPage): title_text = 'Please Wait' body_text = 'Thank you for completing the quiz. On the next screen, you will be asked about your answers for the trivia quiz. Please wait till everyone has finished the trivia quiz.' wait_for_all_groups = True after_all_players_arrive = 'set_state' def is_displayed(self): display = [1, 21, 41, 61] return self.round_number in display class GetQuiz(WaitPage): wait_for_all_groups = True after_all_players_arrive = 'get_quiz' def is_displayed(self): display = [1, 21, 41, 61] return self.round_number not in display class InstructionUpdate(Page): form_model = 'player' form_fields = ['initial_e', 'correct_e'] def is_displayed(self): display = [1, 21, 41, 61] return self.round_number in display @staticmethod def vars_for_template(player): return dict( image_path=C.link[player.participant.whole_img][0] ) class InstructionNeighborUpdate(Page): def is_displayed(self): display = [1, 21, 41, 61] return self.round_number in display and not self.center @staticmethod def vars_for_template(player): neighbor = player.neighbor n = player.group.get_player_by_id(neighbor) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path_neighbor=C.link[n.participant.whole_img][0] ) class CenterInstructionNeighborUpdate(Page): def is_displayed(self): display = [1, 21, 41, 61] return self.round_number in display and self.center @staticmethod def vars_for_template(player): neighbor1 = player.neighbor1 n1 = player.group.get_player_by_id(neighbor1) neighbor2 = player.neighbor2 n2 = player.group.get_player_by_id(neighbor2) neighbor3 = player.neighbor3 n3 = player.group.get_player_by_id(neighbor3) neighbor4 = player.neighbor4 n4 = player.group.get_player_by_id(neighbor4) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path_neighbor1=C.link[n1.participant.whole_img][0], image_path_neighbor2=C.link[n2.participant.whole_img][0], image_path_neighbor3=C.link[n3.participant.whole_img][0], image_path_neighbor4=C.link[n4.participant.whole_img][0] ) class WaitBelief(WaitPage): wait_for_all_groups = True after_all_players_arrive = 'get_belief' class CenterNeighborBeliefUpdate(Page): form_model = 'player' form_fields = ['neighbor1_correct', 'neighbor2_correct', 'neighbor3_correct', 'neighbor4_correct'] def is_displayed(self): display1 = [1, 21, 41, 61] display2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80] display = display1 + display2 return self.round_number in display and self.center @staticmethod def vars_for_template(player): neighbor1 = player.neighbor1 n1 = player.group.get_player_by_id(neighbor1) neighbor2 = player.neighbor2 n2 = player.group.get_player_by_id(neighbor2) neighbor3 = player.neighbor3 n3 = player.group.get_player_by_id(neighbor3) neighbor4 = player.neighbor4 n4 = player.group.get_player_by_id(neighbor4) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path_neighbor1=C.link[n1.participant.whole_img][0], image_path_neighbor2=C.link[n2.participant.whole_img][0], image_path_neighbor3=C.link[n3.participant.whole_img][0], image_path_neighbor4=C.link[n4.participant.whole_img][0] ) class NeighborBeliefUpdate(Page): form_model = 'player' form_fields = ['neighbor_correct'] def is_displayed(self): display1 = [1, 21, 41, 61] display2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80] display = display1 + display2 return self.round_number in display and not self.center @staticmethod def vars_for_template(player): neighbor = player.neighbor n = player.group.get_player_by_id(neighbor) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path_neighbor=C.link[n.participant.whole_img][0] ) class CenterNeighborUpdate(Page): def is_displayed(self): display1 = [1, 21, 41, 61] display2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80] display = display1 + display2 return self.round_number in display and self.center @staticmethod def vars_for_template(player): neighbor1 = player.neighbor1 n1 = player.group.get_player_by_id(neighbor1) neighbor2 = player.neighbor2 n2 = player.group.get_player_by_id(neighbor2) neighbor3 = player.neighbor3 n3 = player.group.get_player_by_id(neighbor3) neighbor4 = player.neighbor4 n4 = player.group.get_player_by_id(neighbor4) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path_neighbor1=C.link[n1.participant.whole_img][0], image_path_neighbor2=C.link[n2.participant.whole_img][0], image_path_neighbor3=C.link[n3.participant.whole_img][0], image_path_neighbor4=C.link[n4.participant.whole_img][0], ) class NeighborUpdate(Page): def is_displayed(self): display1 = [1, 21, 41, 61] display2 = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80] display = display1 + display2 return self.round_number in display and not self.center @staticmethod def vars_for_template(player): neighbor = player.neighbor n = player.group.get_player_by_id(neighbor) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path_neighbor=C.link[n.participant.whole_img][0] ) class CenterSelfUpdate1(Page): form_model = 'player' form_fields = ['answer_e'] def is_displayed(self): display = list(range(1, 21)) return self.round_number in display and self.center @staticmethod def vars_for_template(player): neighbor1 = player.neighbor1 n1 = player.group.get_player_by_id(neighbor1) neighbor2 = player.neighbor2 n2 = player.group.get_player_by_id(neighbor2) neighbor3 = player.neighbor3 n3 = player.group.get_player_by_id(neighbor3) neighbor4 = player.neighbor4 n4 = player.group.get_player_by_id(neighbor4) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path=C.link[player.participant.whole_img][0], image_path_neighbor1=C.link[n1.participant.whole_img][0], image_path_neighbor2=C.link[n2.participant.whole_img][0], image_path_neighbor3=C.link[n3.participant.whole_img][0], image_path_neighbor4=C.link[n4.participant.whole_img][0] ) class SelfUpdate1(Page): form_model = 'player' form_fields = ['answer_e'] def is_displayed(self): display = list(range(1, 21)) return self.round_number in display and not self.center @staticmethod def vars_for_template(player): neighbor = player.neighbor n = player.group.get_player_by_id(neighbor) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path=C.link[player.participant.whole_img][0], image_path_neighbor=C.link[n.participant.whole_img][0] ) class CenterSelfUpdate2(Page): form_model = 'player' form_fields = ['answer_e'] def is_displayed(self): display = list(range(21, 41)) return self.round_number in display and self.center @staticmethod def vars_for_template(player): neighbor1 = player.neighbor1 n1 = player.group.get_player_by_id(neighbor1) neighbor2 = player.neighbor2 n2 = player.group.get_player_by_id(neighbor2) neighbor3 = player.neighbor3 n3 = player.group.get_player_by_id(neighbor3) neighbor4 = player.neighbor4 n4 = player.group.get_player_by_id(neighbor4) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path=C.link[player.participant.whole_img][0], image_path_neighbor1=C.link[n1.participant.whole_img][0], image_path_neighbor2=C.link[n2.participant.whole_img][0], image_path_neighbor3=C.link[n3.participant.whole_img][0], image_path_neighbor4=C.link[n4.participant.whole_img][0] ) class SelfUpdate2(Page): form_model = 'player' form_fields = ['answer_e'] def is_displayed(self): display = list(range(21, 41)) return self.round_number in display and not self.center @staticmethod def vars_for_template(player): neighbor = player.neighbor n = player.group.get_player_by_id(neighbor) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path=C.link[player.participant.whole_img][0], image_path_neighbor=C.link[n.participant.whole_img][0] ) class CenterSelfUpdate3(Page): form_model = 'player' form_fields = ['answer_e'] def is_displayed(self): display = list(range(41, 61)) return self.round_number in display and self.center @staticmethod def vars_for_template(player): neighbor1 = player.neighbor1 n1 = player.group.get_player_by_id(neighbor1) neighbor2 = player.neighbor2 n2 = player.group.get_player_by_id(neighbor2) neighbor3 = player.neighbor3 n3 = player.group.get_player_by_id(neighbor3) neighbor4 = player.neighbor4 n4 = player.group.get_player_by_id(neighbor4) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path=C.link[player.participant.whole_img][0], image_path_neighbor1=C.link[n1.participant.whole_img][0], image_path_neighbor2=C.link[n2.participant.whole_img][0], image_path_neighbor3=C.link[n3.participant.whole_img][0], image_path_neighbor4=C.link[n4.participant.whole_img][0] ) class SelfUpdate3(Page): form_model = 'player' form_fields = ['answer_e'] def is_displayed(self): display = list(range(41, 61)) return self.round_number in display and not self.center @staticmethod def vars_for_template(player): neighbor = player.neighbor n = player.group.get_player_by_id(neighbor) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path=C.link[player.participant.whole_img][0], image_path_neighbor=C.link[n.participant.whole_img][0] ) class CenterSelfUpdate4(Page): form_model = 'player' form_fields = ['answer_e'] def is_displayed(self): display = list(range(61, 81)) return self.round_number in display and self.center @staticmethod def vars_for_template(player): neighbor1 = player.neighbor1 n1 = player.group.get_player_by_id(neighbor1) neighbor2 = player.neighbor2 n2 = player.group.get_player_by_id(neighbor2) neighbor3 = player.neighbor3 n3 = player.group.get_player_by_id(neighbor3) neighbor4 = player.neighbor4 n4 = player.group.get_player_by_id(neighbor4) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path=C.link[player.participant.whole_img][0], image_path_neighbor1=C.link[n1.participant.whole_img][0], image_path_neighbor2=C.link[n2.participant.whole_img][0], image_path_neighbor3=C.link[n3.participant.whole_img][0], image_path_neighbor4=C.link[n4.participant.whole_img][0] ) class SelfUpdate4(Page): form_model = 'player' form_fields = ['answer_e'] def is_displayed(self): display = list(range(61, 81)) return self.round_number in display and not self.center @staticmethod def vars_for_template(player): neighbor = player.neighbor n = player.group.get_player_by_id(neighbor) if player.round_number in list(range(21)): round = player.round_number elif player.round_number in list(range(21, 41)): round = player.round_number - 20 elif player.round_number in list(range(41, 61)): round = player.round_number - 40 else: round = player.round_number - 60 return dict( round=round, image_path=C.link[player.participant.whole_img][0], image_path_neighbor=C.link[n.participant.whole_img][0] ) class WaitPayoff(WaitPage): wait_for_all_groups = True after_all_players_arrive = 'set_payoff' def is_displayed(self): return self.round_number == C.NUM_ROUNDS title_text = 'Please Wait' body_text = 'The experiment is now complete. Thank you for participating. Please wait to see which of the four repetitions was chosen for payment.' class Result(Page): def is_displayed(self): return self.round_number == C.NUM_ROUNDS def vars_for_template(player): if player.session.paying_quiz == 1: pay_round = 1 elif player.session.paying_quiz == 21: pay_round = 2 elif player.session.paying_quiz == 41: pay_round = 3 elif player.session.paying_quiz == 61: pay_round = 4 return dict(pay_round=pay_round) page_sequence = [ShuffleWaitPage, InstructionTrivia, WaitRandom, Trivia1, Trivia2, Trivia3, Trivia4, WaitQuiz, GetQuiz, InstructionUpdate, CenterInstructionNeighborUpdate, InstructionNeighborUpdate, WaitBelief, CenterNeighborBeliefUpdate, NeighborBeliefUpdate, CenterNeighborUpdate, NeighborUpdate, CenterSelfUpdate1, SelfUpdate1, CenterSelfUpdate2, SelfUpdate2, CenterSelfUpdate3, SelfUpdate3, CenterSelfUpdate4, SelfUpdate4, WaitPayoff, Result ]