from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'BG_P_and_F_MismatchPG' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 5 INFOCOST = 3 ENDOWMENT = cu(20) MULTIPLIER = 0.4 INSTRUCTIONSUMPIRE_TEMPLATE = 'BG_P_and_F_MismatchPG/instructionsumpire.html' INSTRUCTIONSPLAYER_TEMPLATE = 'BG_P_and_F_MismatchPG/instructionsplayer.html' INSTRUCTIONSGENERIC_TEMPLATE = 'BG_P_and_F_MismatchPG/instructionsgeneric.html' class Subsession(BaseSubsession): corruzione = models.IntegerField() corruzionesessione = models.IntegerField() robotcorrupt = models.IntegerField() corruzionegruppi = models.IntegerField() corruzioneround = models.IntegerField() corruzioneg1 = models.IntegerField(initial=0) corruzioneg2 = models.IntegerField(initial=0) corruzioneg3 = models.IntegerField(initial=0) corruzioneg4 = models.IntegerField(initial=0) tuttacorruzione = models.IntegerField() def creating_session(subsession: Subsession): session = subsession.session subsession.group_randomly(fixed_id_in_group=True) Subsession.creating_session = creating_session class Group(BaseGroup): contributions = models.IntegerField() individual_share = models.CurrencyField() previous_gain = models.CurrencyField() def after_all_players_arrive(group: Group): #creazione delle stringhe 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(): # stinghe x feedback 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 #why group.round_number == 1? 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 #stringhe x feedback da mostrare al player 2 # if p3.progettocomune == "Uscita": 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 def set_payoff1(group: Group): 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(): group.individual_share = contributions * 0.4 #modifica variabile punizione ai fini del calcolo payoff (la variabile punishment è al livllo del player, ma l'arbitro punisce con ogni variabile un solo giocatore: devo perciò "cancellare" i casi vuoti 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) p1.mazzetta = bribe p.punizione2 = p1.punishment2 * 3 p.punizione3 = p1.punishment3 * 3 p.punizione4 = p1.punishment4 * 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 #payoff participants for p in group.get_players(): p2.payoff = C.ENDOWMENT - p2.contribution + (5 - p2.bribe) + group.individual_share - p2.punizione p3.payoff = C.ENDOWMENT - p3.contribution + (5 - p3.bribe) + group.individual_share - p3.punizione p4.payoff = C.ENDOWMENT - p4.contribution + (5 - p4.bribe) + group.individual_share - p4.punizione 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 p1.bribepl2 = p4.bribepl2 #check p1.bribepl3 = p4.bribepl3 p1.bribepl4 = p4.bribepl4 p.valoremazzetta = p1.bribepl2 + p1.bribepl3 + p1.bribepl4 p1.valoremazzetta = p4.valoremazzetta #payoff arbitro if group.round_number == 1: p1.payoff = 20 + 15 - (p1.punishment2 + p1.punishment3 + p1.punishment4) + p1.valoremazzetta else: p1.payoff = 20 + group.in_round(group.round_number - 1).individual_share + 15 - (p1.punishment2 + p1.punishment3 + p1.punishment4) + p1.valoremazzetta group.previous_gain = group.in_round(group.round_number - 1).individual_share def verify(group: Group): for p in group.get_players(): p1 = group.get_player_by_id(1) p.sumpunishment = p1.punishment2 + p1.punishment3 + p1.punishment4 if p.sumpunishment > 15: #or p1.punizione2 > 10 or p1.punizione3 > 10 or p1.punizione4 > 10 : p.errore = 1 else: p.errore = 0 Group.after_all_players_arrive = after_all_players_arrive Group.set_payoff1 = set_payoff1 class Player(BasePlayer): QuestionPG = models.IntegerField(choices=[[27, '9 (contribuzione) + 9 (contribuzione) + 9 (contribuzione) + 0 (contribuzione) = 27 punti.'], [54, '9 (contribuzione) + 9 (contribuzione) + 9 (contribuzione) + 0 (contribuzione) = 27 punti. 27 x 2 (moltiplicatore progetto comune) = 54 punti']], label='1) Quanto vale il progetto comune?', widget=widgets.RadioSelect) Questionme = models.IntegerField(choices=[[19, '54 : 4 (partecipanti) = 14 punti (quota individuale progetto comune). 14 (dotazione iniziale) - 9 (contribuzione) + 14 = 19 punti'], [28, '54 : 4 (partecipanti) = 14 punti (quota individuale progetto comune). 14 (dotazione iniziale) + 14 = 28 punti']], label="2) Quanti punti ottieni complessivamente, se l'arbitro non ti toglie nessun punto?", widget=widgets.RadioSelect) Question3 = models.IntegerField(choices=[[16, "14 + 12 (quota individuale progetto comune) - 3 (contribuzione) - 7 (punti tolti dall'arbitro) = 16 punti"], [19, "14 + 12 (quota individuale progetto comune) - 7 (punti tolti dall'arbitro) = 19 punti"]], label="3) Quanti punti ottiene complessivamente il partecipante che ha messo 3 punti nel progetto comune, se l'arbitro gli ha tolto 7 punti?", widget=widgets.RadioSelect) QuestionUmp = models.IntegerField(choices=[[17, '17 punti'], [25, '17 + 8 (punti ottenuti grazie al progetto comune) = 25 punti se non accetti i punti offerti '], [27, '17 + 8 (punti ottenuti grazie al progetto comune) + 2 (punti offerti) = 27 punti se accetti i punti offerti']], label='2) Quanti punti ottieni complessivamente?', widget=widgets.RadioSelect) mazzetta = models.IntegerField() punishment2 = 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']], label='Indica se e quanti punti vuoi togliere al partecipante') punishment3 = 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']], label='Indica se e quanti punti vuoi togliere al partecipante') punishment4 = 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']], label='Indica se e quanti punti vuoi togliere al partecipante') bribe2 = models.IntegerField(choices=[[1, 'Si'], [0, 'No']], initial=700, label='Vuoi accettare i punti che ti ha offerto il partecipante?', widget=widgets.RadioSelectHorizontal) bribe3 = models.IntegerField(choices=[[1, 'Si'], [0, 'No']], initial=700, label='Vuoi accettare i punti che ti ha offerto il partecipante?', widget=widgets.RadioSelectHorizontal) bribe4 = models.IntegerField(choices=[[1, 'Si'], [0, 'No']], initial=700, label='Vuoi accettare i punti che ti ha offerto il partecipante?', widget=widgets.RadioSelectHorizontal) bribepl2 = models.IntegerField(choices=[], initial=0) bribepl3 = models.IntegerField(initial=0) bribepl4 = models.IntegerField(initial=0) punizione2 = models.IntegerField(choices=[]) punizione3 = models.IntegerField(choices=[]) punizione4 = models.IntegerField(choices=[]) valoremazzetta = models.IntegerField() punizione = models.IntegerField() progettocomune = models.IntegerField() bribeplayer2 = models.IntegerField() bribeplayer3 = models.IntegerField() bribeplayer4 = models.IntegerField() partecipantipg = models.IntegerField() 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?') bribe = models.IntegerField(choices=[[0, '0'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5']], label="Vuoi offrire dei punti all'aribtro? Quanti?") errore = models.BooleanField(initial=False) progettocomunepl2 = models.IntegerField() progettocomunepl3 = models.IntegerField() progettocomunepl4 = models.IntegerField() sumpunishment = models.IntegerField() def setglobals(player: Player): session = player.session subsession = player.subsession participant = player.participant participant.vars['Human_umpire_payoff'] = participant.payoff #session.vars['corruzionetot'] = subsession.tuttacorruzione return(participant.vars) Player.setglobals = setglobals class Attesagruppixpartire(WaitPage): wait_for_all_groups = True @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Role(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class IstruzioniPlayer(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.round_number == 1 and player.id_in_group != 1 class IstruzioniUmpire(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.round_number == 1 and player.id_in_group == 1 class Start(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 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 class Bribe(Page): form_model = 'player' form_fields = ['bribe'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 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 Punishment2bribe(Page): form_model = 'player' form_fields = ['bribe2', 'punishment2', 'punishment3', 'punishment4', 'bribe3', 'bribe4'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 class VerifyPunishment(WaitPage): after_all_players_arrive = verify @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 class ErrorPunishment(Page): form_model = 'player' form_fields = ['punishment2', 'punishment3', 'punishment4', 'bribe2', 'bribe3', 'bribe4'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 and player.errore == 1 class Attesagiocatori(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 ExecutingPayoffRound1(WaitPage): after_all_players_arrive = set_payoff1 @staticmethod def is_displayed(player: Player): return player.round_number class PayoffRound1(Page): form_model = 'player' @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 == 5 page_sequence = [Attesagruppixpartire, Role, IstruzioniPlayer, IstruzioniUmpire, Start, Contribuzione, Bribe, Giocatori, WaitingUmpire, Punishment2bribe, VerifyPunishment, ErrorPunishment, Attesagiocatori, ExecutingPayoffRound1, PayoffRound1, Ringraziamento]