from otree.api import * c = cu doc = 'endogenous information + exit ' class C(BaseConstants): NAME_IN_URL = 'BG_PENDO_EXIT_B' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 13 INFOCOST = 3 ENDOWMENT = cu(20) INSTRUCTIONSSLIM1_TEMPLATE = 'BG_PENDO_EXIT_B/instructionsslim1.html' class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): session = subsession.session if subsession.round_number == 1: subsession.group_randomly() else: subsession.group_like_round(1) class Group(BaseGroup): contributions = models.IntegerField() total_contribution = models.CurrencyField() individual_share = models.CurrencyField() partecipanti = models.IntegerField() sum_contributions = models.CurrencyField() def after_all_players_arrive(group: Group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) for p in group.get_players(): # variables creaded 4 feedback pages try: p.bribeplayer2 = 0 p1.bribeplayer2 = p2.bribe except TypeError: p2.bribe = None try: p.bribeplayer3 = 0 p1.bribeplayer3 = p3.bribe except TypeError: p3.bribe = None try: p.bribeplayer4 = 0 p1.bribeplayer4 = p4.bribe except TypeError: p4.bribe = None #i created the variable progettocomune for when we will have the exit option (when player exit, contribution = 99 and i need to show in the feedback page "exit"); i think that for now this could be removed for p in group.get_players(): try: p2.progettocomune = p2.contribution except TypeError: p2.contribution = None try: p3.progettocomune = p3.contribution except TypeError: p3.contribution = None try: p4.progettocomune = p4.contribution except TypeError: p4.contribution = None #variables for giving feedback about other players contribution try: p2.progettocomunepl3 = p3.progettocomune p1.progettocomunepl3 = p3.progettocomune p4.progettocomunepl3 = p3.progettocomune except TypeError: p3.progettocomune = None try: p2.progettocomunepl4 = p4.progettocomune p1.progettocomunepl4 = p4.progettocomune p3.progettocomunepl4 = p4.progettocomune except TypeError: p4.progettocomune = None try: p1.progettocomunepl2 = p2.progettocomune p3.progettocomunepl2 = p2.progettocomune p4.progettocomunepl2 = p2.progettocomune except TypeError: p2.progettocomune = None #variable used for feedback in the payoff pages try: if p2.Info == True: p2.infostringa = "Si" else: p2.infostringa = "No" if p3.Info == True: p3.infostringa = "Si" else: p3.infostringa = "No" if p4.Info == True: p4.infostringa = "Si" else: p4.infostringa = "No" except TypeError: p.Info = None try: if p2.exit == 1: p.exitplayer2 = 1 p2.contribution = 0 p.punishment2 = 0 if p3.exit == 1: p.exitplayer3 = 1 p3.contribution = 0 p.punishment3 = 0 if p4.exit == 1: p.exitplayer4 = 1 p4.contribution = 0 p.punishment4 = 0 except TypeError: p.exit = None p1.exitplayer2 = p4.exitplayer2 p2.exitplayer2 = p4.exitplayer2 p3.exitplayer2 = p4.exitplayer2 p1.exitplayer3 = p4.exitplayer3 p2.exitplayer3 = p4.exitplayer3 p3.exitplayer3 = p4.exitplayer3 p1.exitplayer4 = p4.exitplayer4 p2.exitplayer4 = p4.exitplayer4 p3.exitplayer4 = p4.exitplayer4 p.contribuzionepl2 = p2.contribution p.contribuzionepl3 = p3.contribution p.contribuzionepl4 = p4.contribution p2.contribuzionepl2 = p4.contribuzionepl2 p3.contribuzionepl2 = p4.contribuzionepl2 p2.contribuzionepl3 = p4.contribuzionepl3 p3.contribuzionepl3 = p4.contribuzionepl3 p2.contribuzionepl4 = p4.contribuzionepl4 p3.contribuzionepl4 = p4.contribuzionepl4 partecipanti= 0 for p in group.get_players(): try: if p.exit == 0: partecipanti = partecipanti + 1 else: pass except TypeError: p.exit = None group.partecipanti = partecipanti def set_payoff1(group: Group): #payoff round 1 (no info) contributions = 0 bribe = 0 for p in group.get_players(): try: contributions = contributions + p.contribution bribe = bribe + p.bribe except TypeError: p.contribution = None p.bribe = None #individual share is the sum of contributions * mpcr (1.6/4) for p in group.get_players(): if group.partecipanti >= 2: group.individual_share = (contributions * 1.6)/(group.partecipanti + 1) #participants A+umpire group.sum_contributions = contributions else: group.individual_share = 0 for p in group.get_players(): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) # adjusting value of punishment in case of exit #mazzattta = sum of brbes offered p1.mazzetta = bribe #here i creaded a new punishment variable that is a player's field (the punishment variable is originally an umpire's field); all the following variables are create for feedback pages' purposes #punizione2, punizione3, punizione4 = punishment other participants received p.punizione2 = p1.punishment2 * 3 p.punizione3 = p1.punishment3 * 3 p.punizione4 = p1.punishment4 * 3 #punizione = points removed by the umpire *3 p2.punizione = p4.punizione2 p3.punizione = p4.punizione3 p4.punizione = p4.punizione4 p1.punizione2 = p4.punizione2 p2.punizione2 = p4.punizione2 p3.punizione2 = p4.punizione2 p4.punizione2 = p4.punizione2 p1.punizione3 = p4.punizione3 p2.punizione3 = p4.punizione3 p3.punizione3 = p4.punizione3 p4.punizione3 = p4.punizione3 p1.punizione4 = p4.punizione4 p2.punizione4 = p4.punizione4 p3.punizione4 = p4.punizione4 p4.punizione4 = p4.punizione4 p2.bribeplayer2 = p1.bribeplayer2 p3.bribeplayer2 = p1.bribeplayer2 p4.bribeplayer2 = p1.bribeplayer2 p2.bribeplayer3 = p1.bribeplayer3 p3.bribeplayer3 = p1.bribeplayer3 p4.bribeplayer3 = p1.bribeplayer3 p2.bribeplayer4 = p1.bribeplayer4 p3.bribeplayer4 = p1.bribeplayer4 p4.bribeplayer4 = p1.bribeplayer4 #p.contribuzionepl2 = p2.contribution #p.contribuzionepl3 = p3.contribution #p.contribuzionepl4 = p4.contribution #p2.contribuzionepl2 = p4.contribuzionepl2 #p3.contribuzionepl2 = p4.contribuzionepl2 #p2.contribuzionepl3 = p4.contribuzionepl3 #p3.contribuzionepl3 = p4.contribuzionepl3 #p2.contribuzionepl4 = p4.contribuzionepl4 #p3.contribuzionepl4 = p4.contribuzionepl4 #payoff participants round 1 (with no Info) for p in group.get_players(): try: if group.partecipanti >= 2: #if we have at least 2 participants, pg is realized if p2.exit == 0: #participant contributes to pg if p1.bribe2 == 0: #umpire refused the bribe p2.payoff = C.ENDOWMENT - p2.contribution + 5 + group.individual_share - p2.punizione if p1.bribe2 == 1: #umpire accepted the bribe p2.payoff = C.ENDOWMENT - p2.contribution + (5 - p2.bribe) + group.individual_share - p2.punizione if p3.exit == 0: if p1.bribe3 == 1: p3.payoff = C.ENDOWMENT - p3.contribution + (5 - p3.bribe) + group.individual_share - p3.punizione if p1.bribe3 == 0: p3.payoff = C.ENDOWMENT - p3.contribution + 5 + group.individual_share - p3.punizione if p4.exit == 0: if p1.bribe4 == 0: p4.payoff = C.ENDOWMENT - p4.contribution + 5 + group.individual_share - p4.punizione if p1.bribe4 == 1: p4.payoff = C.ENDOWMENT - p4.contribution + (5 - p4.bribe) + group.individual_share - p4.punizione if p2.exit == 1: p2.payoff = 25 if p3.exit == 1: p3.payoff = 25 if p4.exit == 1: p4.payoff = 25 else: p2.payoff = 25 p3.payoff = 25 p4.payoff = 25 except TypeError: p.exit = None if p1.bribe2 == 1: p.bribepl2 = p1.bribeplayer2 p2.bribe2 = p1.bribe2 else: p.bribepl2 = 0 p2.bribe2 = p1.bribe2 if p1.bribe3 == 1: p.bribepl3 = p1.bribeplayer3 p3.bribe3 = p1.bribe3 else: p.bribepl3 = 0 p3.bribe3 = p1.bribe3 if p1.bribe4 == 1: p.bribepl4 = p1.bribeplayer4 p4.bribe4 = p1.bribe4 else: p.bribepl4 = 0 p4.bribe4 = p1.bribe4 p1.bribepl2 = p4.bribepl2 #check p1.bribepl3 = p4.bribepl3 p1.bribepl4 = p4.bribepl4 p2.bribe3 = p1.bribe3 p2.bribe4 = p1.bribe4 p3.bribe2 = p1.bribe2 p3.bribe4 = p1.bribe4 p4.bribe2 = p1.bribe2 p4.bribe3 = p1.bribe3 #valoremazzetta = sum of bribes accepted p.valoremazzetta = p1.bribepl2 + p1.bribepl3 + p1.bribepl4 p1.valoremazzetta = p4.valoremazzetta #payoff arbitro if group.partecipanti == 3: p1.payoff = 20 + group.individual_share + 15 - (p1.punishment2 + p1.punishment3 + p1.punishment4) + p.valoremazzetta elif group.partecipanti == 2 and p.exitplayer2 == 1: p1.payoff = 20 + group.individual_share + 10 - (p1.punishment3 + p1.punishment4) + p.valoremazzetta elif group.partecipanti == 2 and p.exitplayer3 == 1: p1.payoff = 20 + group.individual_share + 10 - (p1.punishment2 + p1.punishment4) + p.valoremazzetta elif group.partecipanti == 2 and p.exitplayer4 == 1: p1.payoff = 20 + group.individual_share + 10 - (p1.punishment2 + p1.punishment3) + p.valoremazzetta elif group.partecipanti == 1: p1.payoff = 20 elif group.partecipanti == 0: p1.payoff = 20 p2.punizione_fb_umpire = p1.punishment2 p3.punizione_fb_umpire = p1.punishment3 p4.punizione_fb_umpire = p1.punishment4 try: if p.exit == 1: p.bribe = 0 else: pass except TypeError: p.exit = None def set_payoff2(group: Group): #payoff round > 1 contributions = 0 bribe = 0 for p in group.get_players(): try: contributions = contributions + p.contribution bribe = bribe + p.bribe except TypeError: p.contribution = None p.bribe = None for p in group.get_players(): if group.partecipanti >= 2: group.individual_share = (contributions * 1.6)/(group.partecipanti + 1) group.sum_contributions = contributions else: group.individual_share = 0 for p in group.get_players(): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) #mazzetta = sum of bribes offered p1.mazzetta = bribe #punizione2, punizione3, punizione4 = punishment other participants received p.punizione2 = p1.punishment2 * 3 p.punizione3 = p1.punishment3 * 3 p.punizione4 = p1.punishment4 * 3 #punizione = points removed by the umpire *3 p2.punizione = p4.punizione2 p3.punizione = p4.punizione3 p4.punizione = p4.punizione4 p1.punizione2 = p4.punizione2 p2.punizione2 = p4.punizione2 p3.punizione2 = p4.punizione2 p4.punizione2 = p4.punizione2 p1.punizione3 = p4.punizione3 p2.punizione3 = p4.punizione3 p3.punizione3 = p4.punizione3 p4.punizione3 = p4.punizione3 p1.punizione4 = p4.punizione4 p2.punizione4 = p4.punizione4 p3.punizione4 = p4.punizione4 p4.punizione4 = p4.punizione4 p2.bribeplayer2 = p1.bribeplayer2 p3.bribeplayer2 = p1.bribeplayer2 p4.bribeplayer2 = p1.bribeplayer2 p2.bribeplayer3 = p1.bribeplayer3 p3.bribeplayer3 = p1.bribeplayer3 p4.bribeplayer3 = p1.bribeplayer3 p2.bribeplayer4 = p1.bribeplayer4 p3.bribeplayer4 = p1.bribeplayer4 p4.bribeplayer4 = p1.bribeplayer4 #p.contribuzionepl2 = p2.contribution #p.contribuzionepl3 = p3.contribution #p.contribuzionepl4 = p4.contribution #p2.contribuzionepl2 = p4.contribuzionepl2 #p3.contribuzionepl2 = p4.contribuzionepl2 #p2.contribuzionepl3 = p4.contribuzionepl3 #p3.contribuzionepl3 = p4.contribuzionepl3 #p2.contribuzionepl4 = p4.contribuzionepl4 #p3.contribuzionepl4 = p4.contribuzionepl4 #payoff participants for p in group.get_players(): try: if group.partecipanti >= 2: #if we have at least 2 participants, pg is realized if p2.exit == 0: # player participate to public good if p2.Info == True: #player bought info if p1.bribe2 == 0: #umpire refused the bribe p2.payoff = C.ENDOWMENT - p2.contribution + 5 + group.individual_share - p2.punizione - C.INFOCOST if p1.bribe2 == 1: #umpire accepted the bribe p2.payoff = C.ENDOWMENT - p2.contribution + (5 - p2.bribe) + group.individual_share - p2.punizione - C.INFOCOST else: #player did not bought info if p1.bribe2 == 0: #umpire refused the bribe2\ p2.payoff = C.ENDOWMENT - p2.contribution + 5 + group.individual_share - p2.punizione if p1.bribe2 == 1: #umpire accepted the bribe p2.payoff = C.ENDOWMENT - p2.contribution + (5 - p2.bribe) + group.individual_share - p2.punizione if p3.exit == 0: if p3.Info == True: #player bought info if p1.bribe3 == 1: p3.payoff = C.ENDOWMENT - p3.contribution + (5 - p3.bribe) + group.individual_share - p3.punizione - C.INFOCOST if p1.bribe3 == 0: p3.payoff = C.ENDOWMENT - p3.contribution + 5 + group.individual_share - p3.punizione - C.INFOCOST else: #player did not bought info if p1.bribe3 == 1: p3.payoff = C.ENDOWMENT - p3.contribution + (5 - p3.bribe) + group.individual_share - p3.punizione if p1.bribe3 == 0: p3.payoff = C.ENDOWMENT - p3.contribution + 5 + group.individual_share - p3.punizione if p4.exit == 0: if p4.Info == True: #player bought info if p1.bribe4 == 0: p4.payoff = C.ENDOWMENT - p4.contribution + 5 + group.individual_share - p4.punizione - C.INFOCOST if p1.bribe4 == 1: p4.payoff = C.ENDOWMENT - p4.contribution + (5 - p4.bribe) + group.individual_share - p4.punizione - C.INFOCOST else: #player did not bought info if p1.bribe4 == 0: p4.payoff = C.ENDOWMENT - p4.contribution + 5 + group.individual_share - p4.punizione if p1.bribe4 == 1: #check this - why red field? p4.payoff = C.ENDOWMENT - p4.contribution + (5 - p4.bribe) + group.individual_share - p4.punizione if p2.exit == 1: # player exit the game if p2.Info == True: #exit with info p2.payoff = 25 - C.INFOCOST else: #exit with no info p2.payoff = 25 if p3.exit == 1:# player exit the game if p3.Info == True: #exit with info p3.payoff = 25 - C.INFOCOST else: #exit with no info p3.payoff = 25 if p4.exit == 1:# player exit the game if p4.Info == True: #exit with info p4.payoff = 25 - C.INFOCOST else: #exit with no info p4.payoff = 25 else: # public good not realized if p2.Info == True: #forced exit with info(group) p2.payoff = 25 - C.INFOCOST else: #forced exit with no info p2.payoff = 25 if p3.Info == True: #forced exit with info p3.payoff = 25 - C.INFOCOST else: #forced exit with no info p3.payoff = 25 if p4.Info == True: #forced exit with info p4.payoff = 25 - C.INFOCOST else: #forced exit with no info p4.payoff = 25 except TypeError: p.exit = None if p1.bribe2 == 1: p.bribepl2 = p1.bribeplayer2 p2.bribe2 = p1.bribe2 else: p.bribepl2 = 0 p2.bribe2 = p1.bribe2 if p1.bribe3 == 1: p.bribepl3 = p1.bribeplayer3 p3.bribe3 = p1.bribe3 else: p.bribepl3 = 0 p3.bribe3 = p1.bribe3 if p1.bribe4 == 1: p.bribepl4 = p1.bribeplayer4 p4.bribe4 = p1.bribe4 else: p.bribepl4 = 0 p4.bribe4 = p1.bribe4 p1.bribepl2 = p4.bribepl2 #check p1.bribepl3 = p4.bribepl3 p1.bribepl4 = p4.bribepl4 p2.bribe3 = p1.bribe3 p2.bribe4 = p1.bribe4 p3.bribe2 = p1.bribe2 p3.bribe4 = p1.bribe4 p4.bribe2 = p1.bribe2 p4.bribe3 = p1.bribe3 #valoremazzetta = sum of bribes accepted p.valoremazzetta = p1.bribepl2 + p1.bribepl3 + p1.bribepl4 p1.valoremazzetta = p4.valoremazzetta #payoff arbitro #if group.partecipanti >= 2: # p1.payoff = 20 + group.individual_share + 15 - (p1.punishment2 + p1.punishment3 + p1.punishment4) + p.valoremazzetta #else: # p1.payoff = 20 if group.partecipanti == 3: p1.payoff = 20 + group.individual_share + 15 - (p1.punishment2 + p1.punishment3 + p1.punishment4) + p.valoremazzetta elif group.partecipanti == 2 and p.exitplayer2 == 1: p1.payoff = 20 + group.individual_share + 10 - (p1.punishment3 + p1.punishment4) + p.valoremazzetta elif group.partecipanti == 2 and p.exitplayer3 == 1: p1.payoff = 20 + group.individual_share + 10 - (p1.punishment2 + p1.punishment4) + p.valoremazzetta elif group.partecipanti == 2 and p.exitplayer4 == 1: p1.payoff = 20 + group.individual_share + 10 - (p1.punishment2 + p1.punishment3) + p.valoremazzetta elif group.partecipanti == 1: p1.payoff = 20 elif group.partecipanti == 0: p1.payoff = 20 if p1.bribe2 == 1: p.bribepl2 = p1.bribeplayer2 else: p.bribepl2 = 0 if p1.bribe3 == 1: p.bribepl3 = p1.bribeplayer3 else: p.bribepl3 = 0 if p1.bribe4 == 1: p.bribepl4 = p1.bribeplayer4 else: p.bribepl4 = 0 p2.punizione_fb_umpire = p1.punishment2 p3.punizione_fb_umpire = p1.punishment3 p4.punizione_fb_umpire = p1.punishment4 try: if p2.exit == 1: p2.bribe = 0 else: pass if p3.exit == 1: p3.bribe = 0 else: pass if p4.exit == 1: p4.bribe = 0 else: pass except TypeError: p.exit = None def fase_uno(group: Group): #this is for feedback after Fase 1 - it isn't used in this version, consider removing it for p in group.get_players(): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) contributions = 0 for p in group.get_players(): try: contributions = contributions + p.contribution except TypeError: p.contribution = None for p in group.get_players(): group.total_contribution = contributions * 1.6 group.individual_share = contributions * 0.4 #payoff participants for p in group.get_players(): p2.faseuno = 20 - p2.contribution + group.individual_share p3.faseuno = 20 - p3.contribution + group.individual_share p4.faseuno = 20 - p4.contribution + group.individual_share p1.faseuno = 0 for p in group.get_players(): p2.redditoprivato = C.ENDOWMENT - p2.contribution p3.redditoprivato = C.ENDOWMENT - p3.contribution p4.redditoprivato = C.ENDOWMENT - p4.contribution p1.redditoprivato = 0 def info(group: Group): #creation variables for information page for p in group.get_players(): p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) p.contributionbeforepl2 = p2.in_round(group.round_number - 1).contribuzionepl2 p.contributionbeforepl3 = p3.in_round(group.round_number - 1).contribuzionepl3 p.contributionbeforepl4 = p4.in_round(group.round_number - 1).contribuzionepl4 p.bribeacceptancepl2 = p2.in_round(group.round_number - 1).bribe2 p.bribeacceptancepl3 = p3.in_round(group.round_number - 1).bribe3 p.bribeacceptancepl4 = p4.in_round(group.round_number - 1).bribe4 p.punizionebeforepl2 = p.in_round(group.round_number - 1).punizione2 p.punizionebeforepl3 = p.in_round(group.round_number - 1).punizione3 p.punizionebeforepl4 = p.in_round(group.round_number - 1).punizione4 p.bribebeforepl2 = p.in_round(group.round_number - 1).bribeplayer2 p.bribebeforepl3 = p.in_round(group.round_number - 1).bribeplayer3 p.bribebeforepl4 = p.in_round(group.round_number - 1).bribeplayer4 p.partecipantibefore = group.in_round(group.round_number-1).partecipanti p.exitplayer2before = p.in_round(group.round_number-1).exitplayer2 p.exitplayer3before = p.in_round(group.round_number-1).exitplayer3 p.exitplayer4before = p.in_round(group.round_number-1).exitplayer4 try: p.exitbefore = p.in_round(group.round_number-1).exit except TypeError: p.exitbefore = None def adjustingexitfields(group: Group): for p in group.get_players(): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) # adjusting value of punishment in case of exit for p in group.get_players(): try: if p.punishment2 == 700: p1.punishment2 = 0 p2.punishment2 = 0 p3.punishment2 = 0 p4.punishment2 = 0 elif p.punishment3 == 700: p1.punishment3 = 0 p2.punishment3 = 0 p3.punishment3 = 0 p4.punishment3 = 0 elif p.punishment4 == 700: p1.punishment4 = 0 p2.punishment4 = 0 p3.punishment4 = 0 p4.punishment4 = 0 except TypeError: p.punishment2 = None p.punishment3 = None p.punishment4 = None Group.after_all_players_arrive = after_all_players_arrive Group.set_payoff1 = set_payoff1 Group.set_payoff2 = set_payoff2 class Player(BasePlayer): Questionbribe = models.IntegerField(choices=[[25, '20 - 10 + 12 + 5 - 2 = 25'], [20, '20 - 10 + 12 - 2 = 20']], label='3) Quanti punti ottieni se trasferisci 2 punti al partecipante B?', widget=widgets.RadioSelect) Questionme = models.IntegerField(choices=[[32, '30 x 1.6 = 48. 48: 4 = 12. 20 + 12 = 32'], [27, '30 x 1.6 = 48. 48 : 4 = 12. 20 - 10 + 12 + 5 = 27']], label='1) Quanti punti ottieni alla fine del periodo, se il partecipante B non ti toglie nessun punto?', widget=widgets.RadioSelect) Question3 = models.IntegerField(choices=[[23, '20 + 12 - 9 = 23'], [18, '20 - 10 + 12 + 5 - 9 = 18']], label='2) Quanti punti ottieni alla fine del periodo, se il partecipante B ti toglie 9 punti?', widget=widgets.RadioSelect) QuestionExit = models.IntegerField(choices=[[33, '20 x 1.6 = 32. 32 : 4 = 8. 20 + 5 + 8 = 33'], [25, '20 + 5 = 25']], label='4) Quanti punti ottieni se decidi di non partecipare al progetto comune?', widget=widgets.RadioSelect) exit = models.IntegerField(choices=[[0, 'Si'], [1, 'No']], label='Vuoi partecipare al progetto comune?', widget=widgets.RadioSelect) contribution = models.IntegerField(choices=[[0, '0'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, '10'], [11, '11'], [12, '12'], [13, '13'], [14, '14'], [15, '15'], [16, '16'], [17, '17'], [18, '18'], [19, '19'], [20, '20']], label='Quanto vuoi mettere nel progetto comune?') redditoprivato = models.CurrencyField() faseuno = models.CurrencyField() bribe = models.IntegerField(choices=[[0, 'Nessun punto'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5']], label='Hai a disposizione 5 punti. Indica se e quanti punti vuoi trasferire al Partecipante B ') bribe2 = models.IntegerField(choices=[[1, 'Si'], [0, 'No']], initial=700, label='Vuoi accettare i punti che ti ha trasferito il partecipante?', widget=widgets.RadioSelectHorizontal) bribe3 = models.IntegerField(choices=[[1, 'Si'], [0, 'No']], initial=700, label='Vuoi accettare i punti che ti ha trasferito il partecipante?', widget=widgets.RadioSelectHorizontal) bribe4 = models.IntegerField(choices=[[1, 'Si'], [0, 'No']], initial=700, label='Vuoi accettare i punti che ti ha trasferito il partecipante?', widget=widgets.RadioSelectHorizontal) punishment2 = models.IntegerField(choices=[[0, 'Nessun punto'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, '10']], initial=700, label='Indica se e quanti punti vuoi togliere al partecipante ') punishment3 = models.IntegerField(choices=[[0, 'Nessun punto'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, '10']], initial=700, label='Indica se e quanti punti vuoi togliere al partecipante ') punishment4 = models.IntegerField(choices=[[0, 'Nessun punto'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, '10']], initial=700, label='Indica se e quanti punti vuoi togliere al partecipante') mazzetta = models.IntegerField() valoremazzetta = models.IntegerField() bribepl2 = models.IntegerField(choices=[], initial=0) bribepl3 = models.IntegerField(initial=0) bribepl4 = models.IntegerField(initial=0) bribepl5 = models.IntegerField(initial=0) punizione2 = models.IntegerField(choices=[]) punizione3 = models.IntegerField(choices=[]) punizione4 = models.IntegerField(choices=[]) punizione = models.IntegerField() punizione_fb_umpire = models.IntegerField() progettocomune = models.IntegerField() progettocomunepl2 = models.IntegerField() progettocomunepl3 = models.IntegerField() progettocomunepl4 = models.IntegerField() bribeplayer2 = models.IntegerField() bribeplayer3 = models.IntegerField() bribeplayer4 = models.IntegerField() Info = models.BooleanField(choices=[[True, 'Si'], [False, 'No']], label="Vuoi comprare un'informazione sulle decisioni prese dal Partecipante B nel periodo precedente, al costo di 3 punti?", widget=widgets.RadioSelect) infostringa = models.StringField(initial='-') contribuzionepl2 = models.IntegerField() contribuzionepl3 = models.IntegerField() contribuzionepl4 = models.IntegerField() bribeacceptancepl2 = models.IntegerField() bribeacceptancepl3 = models.IntegerField() bribeacceptancepl4 = models.IntegerField() contributionbeforepl2 = models.IntegerField() contributionbeforepl3 = models.IntegerField() contributionbeforepl4 = models.IntegerField() bribebeforepl2 = models.IntegerField() bribebeforepl3 = models.IntegerField() bribebeforepl4 = models.IntegerField() punizionebeforepl2 = models.IntegerField() punizionebeforepl3 = models.IntegerField() punizionebeforepl4 = models.IntegerField() exitplayer2 = models.IntegerField(initial=0) exitplayer3 = models.IntegerField(initial=0) exitplayer4 = models.IntegerField(initial=0) partecipantibefore = models.IntegerField() exitplayer2before = models.IntegerField(initial=0) exitplayer3before = models.IntegerField(initial=0) exitplayer4before = models.IntegerField(initial=0) exitbefore = models.IntegerField() partecipantibefor = models.IntegerField() def setglobals(player: Player): participant = player.participant participant.vars['BG_payoff'] = participant.payoff return(participant.vars) def other_player(player: Player): group = player.group return player.get_others_in_group() Player.setglobals = setglobals class Attesagruppixpartire(WaitPage): wait_for_all_groups = True @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Istruzioni(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Instruction_II(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Instruction_III(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Instruction_IV(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Questions(Page): form_model = 'player' form_fields = ['Questionme', 'Question3', 'Questionbribe', 'QuestionExit'] @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def error_message(player: Player, values): print ('values is', values) if values['Questionme'] != 27 or values['Questionbribe'] !=25 or values['Question3'] != 18 or values['QuestionExit'] != 25: return 'Attenzione: Per procedere รจ necessario rispondere correttamente a tutte le domande. Per favore controlla le tue risposte.' class Role(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Start(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Info(Page): form_model = 'player' form_fields = ['Info'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 and player.round_number != 1 class ElaboratingInfo(WaitPage): after_all_players_arrive = info @staticmethod def is_displayed(player: Player): return player.round_number != 1 class DiscoveryUmpire(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.round_number != 1 and player.id_in_group != 1 and player.Info == True class Exit(Page): form_model = 'player' form_fields = ['exit'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 class Contribuzione(Page): form_model = 'player' form_fields = ['contribution'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 and player.exit == 0 class Bribe_Fase2(Page): form_model = 'player' form_fields = ['bribe'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 and player.exit == 0 class Giocatori(WaitPage): after_all_players_arrive = after_all_players_arrive @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 class WaitingUmpire(WaitPage): after_all_players_arrive = after_all_players_arrive body_text = 'Attendi che i partecipanti facciano le loro scelte' @staticmethod def is_displayed(player: Player): group = player.group return group.get_player_by_id(1) class Punishment(Page): form_model = 'player' form_fields = ['bribe2', 'punishment2', 'bribe3', 'punishment3', 'bribe4', 'punishment4'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 and player.exitplayer2 == 0 and player.exitplayer3 == 0 and player.exitplayer4 == 0 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) @staticmethod def error_message(player: Player, values): print ('values is', values) if values['punishment2'] + values['punishment3'] + values['punishment4'] > 15: return 'Attenzione: Puoi rimuovere in totale 15 punti. Per favore effettua nuovamente la tua scelta.' class PunishmentExit2(Page): form_model = 'player' form_fields = ['bribe3', 'bribe4', 'punishment3', 'punishment4'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 and player.exitplayer2 == 1 and player.exitplayer3 == 0 and player.exitplayer4 == 0 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) @staticmethod def error_message(player: Player, values): print ('values is', values) if values['punishment3'] + values['punishment4'] > 10: return 'Attenzione: Puoi rimuovere in totale 10 punti. Per favore effettua nuovamente la tua scelta.' class PunishmentExit3(Page): form_model = 'player' form_fields = ['bribe2', 'bribe4', 'punishment2', 'punishment4'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 and player.exitplayer2 == 0 and player.exitplayer3 == 1 and player.exitplayer4 == 0 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) @staticmethod def error_message(player: Player, values): print ('values is', values) if values['punishment2'] + values['punishment4'] > 10: return 'Attenzione: Puoi rimuovere in totale 10 punti. Per favore effettua nuovamente la tua scelta.' class PunishmentExit4(Page): form_model = 'player' form_fields = ['bribe2', 'bribe3', 'punishment2', 'punishment3'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 and player.exitplayer2 == 0 and player.exitplayer3 == 0 and player.exitplayer4 == 1 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) @staticmethod def error_message(player: Player, values): print ('values is', values) if values['punishment3'] + values['punishment2'] > 10: return 'Attenzione: Puoi rimuovere in totale 10 punti. Per favore effettua nuovamente la tua scelta.' class PunishmentExit23(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 and player.exitplayer2 ==1 and player.exitplayer3 == 1 and player.exitplayer4 == 0 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) class PunishmentExit24(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 and player.exitplayer2 == 1 and player.exitplayer3 == 0 and player.exitplayer4 == 1 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) class PunishmentExit34(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 and player.exitplayer2 == 0 and player.exitplayer3 == 1 and player.exitplayer4 == 1 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) class PunishmentExitAll(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 and player.exitplayer2 == 1 and player.exitplayer3 == 1 and player.exitplayer4 == 1 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) class Attesagiocatori(WaitPage): after_all_players_arrive = after_all_players_arrive @staticmethod def is_displayed(player: Player): pass class ExecutingPayoffRound1(WaitPage): after_all_players_arrive = set_payoff1 @staticmethod def is_displayed(player: Player): return player.round_number == 1 class ExecutingPayoff2(WaitPage): after_all_players_arrive = set_payoff2 @staticmethod def is_displayed(player: Player): return player.round_number != 1 class PayoffRound1(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) @staticmethod def before_next_page(player: Player, timeout_happened): player.setglobals() class Payoff2(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 3 or player.round_number == 4 or player.round_number == 6 or player.round_number == 8 or player.round_number == 9 or player.round_number == 11 or player.round_number == 13 or player.round_number == 14 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) @staticmethod def before_next_page(player: Player, timeout_happened): player.setglobals() class Payoff2Reshuffle(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 2 or player.round_number == 5 or player.round_number == 7 or player.round_number == 10 or player.round_number == 12 or player.round_number == 15 @staticmethod def vars_for_template(player: Player): other = other_player(player) if player.round_number == 1 or player.round_number == 2 or player.round_number == 7 or player.round_number == 9 or player.round_number == 12: return dict( other_ordered = [other[0],other[1], other[2]] ) elif player.round_number == 3 or player.round_number == 6 or player.round_number == 10 or player.round_number == 13 or player.round_number == 15: return dict( other_ordered = [other[1],other[2], other[0]] ) else: return dict( other_ordered = [other[2],other[0], other[1]] ) @staticmethod def before_next_page(player: Player, timeout_happened): player.setglobals() class Ringraziamento(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 13 page_sequence = [Attesagruppixpartire, Istruzioni, Instruction_II, Instruction_III, Instruction_IV, Questions, Role, Start, Info, ElaboratingInfo, DiscoveryUmpire, Exit, Contribuzione, Bribe_Fase2, Giocatori, WaitingUmpire, Punishment, PunishmentExit2, PunishmentExit3, PunishmentExit4, PunishmentExit23, PunishmentExit24, PunishmentExit34, PunishmentExitAll, Attesagiocatori, ExecutingPayoffRound1, ExecutingPayoff2, PayoffRound1, Payoff2, Payoff2Reshuffle, Ringraziamento]