######################################################################################################################## # Imports. ######################################################################################################################## import cgi from otree.api import * from . import * ######################################################################################################################## # Bots instructions: # When playing t2, use the help_other_matrix with the 2s. When not, use the other one. # When playing t2 or t0, use the link_severed_to_others_matrix with the Nones. WHen not, use the other one. ######################################################################################################################## test_case = 2 # 1: batch; 2: matrix class PlayerBot(Bot): def play_round(self): if self.session.config['treatment'] == 2: link_to_others_matrix = [ # Round/player/links [T2] [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], [[1, 1, 0, 1], [0, 1, 1, 1], [1, 1, 1, 0], [1, 1, 0, 1]], [[0, 0, 0, 1], [0, 0, 1, 0], [1, 0, 1, 1], [1, 0, 0, 0]], [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], ] link_severed_to_others_matrix = [ # Round/player/links [T2, T0]] [[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]], [[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]], [[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]], [[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]], ] help_others_matrix = [ # Round/help [T2] [2, 2, 2, 2], [2, 2, 0, 1], [2, 1, 2, 0], [1, 1, 1, 1], ] print("Bot Treatment:", 2) elif self.session.config['treatment'] == 1: link_to_others_matrix = [ # Round/player/links [T1] [[1, 1, 0, 0], [0, 1, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 1, 1], [0, 1, 0, 1], [1, 0, 1, 0], [0, 0, 0, 0]], [[0, 1, 1, 0], [0, 1, 1, 1], [0, 0, 0, 0], [0, 1, 1, 0]], [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], ] link_severed_to_others_matrix = [ # Round/player/links [T1] [[0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [1, 1, 1, 1]], [[1, 0, 0, 0], [0, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], ] help_others_matrix = [ # Round/help [T1] [1, 1, 1, 1], [0, 0, 1, 1], [1, 0, 1, 0], [1, 1, 1, 1], ] print("Bot Treatment:", 1) elif self.session.config['treatment'] == 0: link_to_others_matrix = [ # Round/player/links [T2] [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], [[1, 1, 0, 1], [0, 1, 1, 1], [1, 1, 1, 0], [1, 1, 0, 1]], [[0, 0, 0, 1], [0, 0, 1, 0], [1, 0, 1, 1], [1, 0, 0, 0]], [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], ] link_severed_to_others_matrix = [ # Round/player/links [T2, T0]] [[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]], [[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]], [[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]], [[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]], ] help_others_matrix = [ # Round/help [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], ] print("Bot Treatment:", 0) if test_case == 2: # This tests individual player decisions up to round []. Afterwards it automates as test_case = 1. if self.participant.finished_rounds == False: print("ROUND NUMBER IN BOTS", self.round_number) if self.round_number == 1: # ROUND 1: if self.player.id_in_group % 2 != 0: # for blue players yield Results if self.player.id_in_group == 1: yield Submission(BlueChooses, dict(link_to_p2=link_to_others_matrix[0][0][0], link_to_p4=link_to_others_matrix[0][0][1], link_to_p6=link_to_others_matrix[0][0][2], link_to_p8=link_to_others_matrix[0][0][3], link_severed_to_p2=link_severed_to_others_matrix[0][0][0], link_severed_to_p4=link_severed_to_others_matrix[0][0][1], link_severed_to_p6=link_severed_to_others_matrix[0][0][2], link_severed_to_p8=link_severed_to_others_matrix[0][0][3], ), check_html=False) elif self.player.id_in_group == 3: yield Submission(BlueChooses, dict(link_to_p2=link_to_others_matrix[0][1][0], link_to_p4=link_to_others_matrix[0][1][1], link_to_p6=link_to_others_matrix[0][1][2], link_to_p8=link_to_others_matrix[0][1][3], link_severed_to_p2=link_severed_to_others_matrix[0][1][0], link_severed_to_p4=link_severed_to_others_matrix[0][1][1], link_severed_to_p6=link_severed_to_others_matrix[0][1][2], link_severed_to_p8=link_severed_to_others_matrix[0][1][3], ), check_html=False) elif self.player.id_in_group == 5: yield Submission(BlueChooses, dict(link_to_p2=link_to_others_matrix[0][2][0], link_to_p4=link_to_others_matrix[0][2][1], link_to_p6=link_to_others_matrix[0][2][2], link_to_p8=link_to_others_matrix[0][2][3], link_severed_to_p2=link_severed_to_others_matrix[0][2][0], link_severed_to_p4=link_severed_to_others_matrix[0][2][1], link_severed_to_p6=link_severed_to_others_matrix[0][2][2], link_severed_to_p8=link_severed_to_others_matrix[0][2][3], ), check_html=False) elif self.player.id_in_group == 7: yield Submission(BlueChooses, dict(link_to_p2=link_to_others_matrix[0][3][0], link_to_p4=link_to_others_matrix[0][3][1], link_to_p6=link_to_others_matrix[0][3][2], link_to_p8=link_to_others_matrix[0][3][3], link_severed_to_p2=link_severed_to_others_matrix[0][3][0], link_severed_to_p4=link_severed_to_others_matrix[0][3][1], link_severed_to_p6=link_severed_to_others_matrix[0][3][2], link_severed_to_p8=link_severed_to_others_matrix[0][3][3], ), check_html=False) if self.participant.finished_rounds == True: yield BlockEnd elif self.player.id_in_group % 2 == 0: if self.player.id_in_group == 2: yield RedChooses, dict(help_others=help_others_matrix[0][0]) elif self.player.id_in_group == 4: yield RedChooses, dict(help_others=help_others_matrix[0][1]) elif self.player.id_in_group == 6: yield RedChooses, dict(help_others=help_others_matrix[0][2]) elif self.player.id_in_group == 8: yield RedChooses, dict(help_others=help_others_matrix[0][3]) yield Results if self.participant.finished_rounds == True: yield BlockEnd elif self.round_number == 2: # ROUND 2: if self.player.id_in_group % 2 == 0: # for blue players yield Results if self.player.id_in_group == 2: yield Submission(BlueChooses, dict(link_to_p1=link_to_others_matrix[1][0][0], link_to_p3=link_to_others_matrix[1][0][1], link_to_p5=link_to_others_matrix[1][0][2], link_to_p7=link_to_others_matrix[1][0][3], link_severed_to_p1=link_severed_to_others_matrix[1][0][0], link_severed_to_p3=link_severed_to_others_matrix[1][0][1], link_severed_to_p5=link_severed_to_others_matrix[1][0][2], link_severed_to_p7=link_severed_to_others_matrix[1][0][3], ), check_html=False) elif self.player.id_in_group == 4: yield Submission(BlueChooses, dict(link_to_p1=link_to_others_matrix[1][1][0], link_to_p3=link_to_others_matrix[1][1][1], link_to_p5=link_to_others_matrix[1][1][2], link_to_p7=link_to_others_matrix[1][1][3], link_severed_to_p1=link_severed_to_others_matrix[1][1][0], link_severed_to_p3=link_severed_to_others_matrix[1][1][1], link_severed_to_p5=link_severed_to_others_matrix[1][1][2], link_severed_to_p7=link_severed_to_others_matrix[1][1][3], ), check_html=False) elif self.player.id_in_group == 6: yield Submission(BlueChooses, dict(link_to_p1=link_to_others_matrix[1][2][0], link_to_p3=link_to_others_matrix[1][2][1], link_to_p5=link_to_others_matrix[1][2][2], link_to_p7=link_to_others_matrix[1][2][3], link_severed_to_p1=link_severed_to_others_matrix[1][2][0], link_severed_to_p3=link_severed_to_others_matrix[1][2][1], link_severed_to_p5=link_severed_to_others_matrix[1][2][2], link_severed_to_p7=link_severed_to_others_matrix[1][2][3], ), check_html=False) elif self.player.id_in_group == 8: yield Submission(BlueChooses, dict(link_to_p1=link_to_others_matrix[1][3][0], link_to_p3=link_to_others_matrix[1][3][1], link_to_p5=link_to_others_matrix[1][3][2], link_to_p7=link_to_others_matrix[1][3][3], link_severed_to_p1=link_severed_to_others_matrix[1][3][0], link_severed_to_p3=link_severed_to_others_matrix[1][3][1], link_severed_to_p5=link_severed_to_others_matrix[1][3][2], link_severed_to_p7=link_severed_to_others_matrix[1][3][3], ), check_html=False) if self.participant.finished_rounds == True: yield BlockEnd elif self.player.id_in_group % 2 != 0: if self.player.id_in_group == 1: yield RedChooses, dict(help_others=help_others_matrix[1][0]) elif self.player.id_in_group == 3: yield RedChooses, dict(help_others=help_others_matrix[1][1]) elif self.player.id_in_group == 5: yield RedChooses, dict(help_others=help_others_matrix[1][2]) elif self.player.id_in_group == 7: yield RedChooses, dict(help_others=help_others_matrix[1][3]) yield Results if self.participant.finished_rounds == True: yield BlockEnd elif self.round_number == 3: # ROUND 1: if self.player.id_in_group % 2 != 0: # for blue players yield Results if self.player.id_in_group == 1: yield Submission(BlueChooses, dict(link_to_p2=link_to_others_matrix[2][0][0], link_to_p4=link_to_others_matrix[2][0][1], link_to_p6=link_to_others_matrix[2][0][2], link_to_p8=link_to_others_matrix[2][0][3], link_severed_to_p2=link_severed_to_others_matrix[2][0][0], link_severed_to_p4=link_severed_to_others_matrix[2][0][1], link_severed_to_p6=link_severed_to_others_matrix[2][0][2], link_severed_to_p8=link_severed_to_others_matrix[2][0][3], ), check_html=False) elif self.player.id_in_group == 3: yield Submission(BlueChooses, dict(link_to_p2=link_to_others_matrix[2][1][0], link_to_p4=link_to_others_matrix[2][1][1], link_to_p6=link_to_others_matrix[2][1][2], link_to_p8=link_to_others_matrix[2][1][3], link_severed_to_p2=link_severed_to_others_matrix[2][1][0], link_severed_to_p4=link_severed_to_others_matrix[2][1][1], link_severed_to_p6=link_severed_to_others_matrix[2][1][2], link_severed_to_p8=link_severed_to_others_matrix[2][1][3], ), check_html=False) elif self.player.id_in_group == 5: yield Submission(BlueChooses, dict(link_to_p2=link_to_others_matrix[2][2][0], link_to_p4=link_to_others_matrix[2][2][1], link_to_p6=link_to_others_matrix[2][2][2], link_to_p8=link_to_others_matrix[2][2][3], link_severed_to_p2=link_severed_to_others_matrix[2][2][0], link_severed_to_p4=link_severed_to_others_matrix[2][2][1], link_severed_to_p6=link_severed_to_others_matrix[2][2][2], link_severed_to_p8=link_severed_to_others_matrix[2][2][3], ), check_html=False) elif self.player.id_in_group == 7: yield Submission(BlueChooses, dict(link_to_p2=link_to_others_matrix[2][3][0], link_to_p4=link_to_others_matrix[2][3][1], link_to_p6=link_to_others_matrix[2][3][2], link_to_p8=link_to_others_matrix[2][3][3], link_severed_to_p2=link_severed_to_others_matrix[2][3][0], link_severed_to_p4=link_severed_to_others_matrix[2][3][1], link_severed_to_p6=link_severed_to_others_matrix[2][3][2], link_severed_to_p8=link_severed_to_others_matrix[2][3][3], ), check_html=False) if self.participant.finished_rounds == True: yield BlockEnd elif self.player.id_in_group % 2 == 0: if self.player.id_in_group == 2: yield RedChooses, dict(help_others=help_others_matrix[2][0]) elif self.player.id_in_group == 4: yield RedChooses, dict(help_others=help_others_matrix[2][1]) elif self.player.id_in_group == 6: yield RedChooses, dict(help_others=help_others_matrix[2][2]) elif self.player.id_in_group == 8: yield RedChooses, dict(help_others=help_others_matrix[2][3]) yield Results if self.participant.finished_rounds == True: yield BlockEnd elif self.round_number == 4: # ROUND 2: if self.player.id_in_group % 2 == 0: # for blue players yield Results if self.player.id_in_group == 2: yield Submission(BlueChooses, dict(link_to_p1=link_to_others_matrix[3][0][0], link_to_p3=link_to_others_matrix[3][0][1], link_to_p5=link_to_others_matrix[3][0][2], link_to_p7=link_to_others_matrix[3][0][3], link_severed_to_p1=link_severed_to_others_matrix[3][0][0], link_severed_to_p3=link_severed_to_others_matrix[3][0][1], link_severed_to_p5=link_severed_to_others_matrix[3][0][2], link_severed_to_p7=link_severed_to_others_matrix[3][0][3], ), check_html=False) elif self.player.id_in_group == 4: yield Submission(BlueChooses, dict(link_to_p1=link_to_others_matrix[3][1][0], link_to_p3=link_to_others_matrix[3][1][1], link_to_p5=link_to_others_matrix[3][1][2], link_to_p7=link_to_others_matrix[3][1][3], link_severed_to_p1=link_severed_to_others_matrix[3][1][0], link_severed_to_p3=link_severed_to_others_matrix[3][1][1], link_severed_to_p5=link_severed_to_others_matrix[3][1][2], link_severed_to_p7=link_severed_to_others_matrix[3][1][3], ), check_html=False) elif self.player.id_in_group == 6: yield Submission(BlueChooses, dict(link_to_p1=link_to_others_matrix[3][2][0], link_to_p3=link_to_others_matrix[3][2][1], link_to_p5=link_to_others_matrix[3][2][2], link_to_p7=link_to_others_matrix[3][2][3], link_severed_to_p1=link_severed_to_others_matrix[3][2][0], link_severed_to_p3=link_severed_to_others_matrix[3][2][1], link_severed_to_p5=link_severed_to_others_matrix[3][2][2], link_severed_to_p7=link_severed_to_others_matrix[3][2][3], ), check_html=False) elif self.player.id_in_group == 8: yield Submission(BlueChooses, dict(link_to_p1=link_to_others_matrix[3][3][0], link_to_p3=link_to_others_matrix[3][3][1], link_to_p5=link_to_others_matrix[3][3][2], link_to_p7=link_to_others_matrix[3][3][3], link_severed_to_p1=link_severed_to_others_matrix[3][3][0], link_severed_to_p3=link_severed_to_others_matrix[3][3][1], link_severed_to_p5=link_severed_to_others_matrix[3][3][2], link_severed_to_p7=link_severed_to_others_matrix[3][3][3], ), check_html=False) if self.participant.finished_rounds == True: yield BlockEnd elif self.player.id_in_group % 2 != 0: if self.player.id_in_group == 1: yield RedChooses, dict(help_others=help_others_matrix[3][0]) elif self.player.id_in_group == 3: yield RedChooses, dict(help_others=help_others_matrix[3][1]) elif self.player.id_in_group == 5: yield RedChooses, dict(help_others=help_others_matrix[3][2]) elif self.player.id_in_group == 7: yield RedChooses, dict(help_others=help_others_matrix[3][3]) yield Results if self.participant.finished_rounds == True: yield BlockEnd links_to = 1 severe = 1 # (0,1) if self.session.config['treatment'] == 0 or self.session.config['treatment'] == 1: # THIS CODE REPLICATES elif test_case == 1: help_or_trade_bot = 0 # (0,1) elif self.session.config['treatment'] == 2: help_or_trade_bot = 2 # (0,1,2) if self.participant.finished_rounds == False: print("ROUND NUMBER IN BOTS", self.round_number) if self.round_number % 2 != 0 and self.round_number >= 5: if self.player.id_in_group % 2 != 0: # for blue players yield Results yield Submission(BlueChooses, dict(link_to_p2=links_to, link_to_p4=links_to, link_to_p6=links_to, link_to_p8=links_to, link_severed_to_p2=severe, link_severed_to_p4=severe, link_severed_to_p6=severe, link_severed_to_p8=severe, ), check_html=False) if self.participant.finished_rounds == True: yield BlockEnd elif self.player.id_in_group % 2 == 0: yield RedChooses, dict(help_others=help_or_trade_bot) yield Results if self.participant.finished_rounds == True: yield BlockEnd elif self.round_number % 2 == 0 and self.round_number >= 6: if self.player.id_in_group % 2 == 0: # for blue players yield Results yield Submission(BlueChooses, dict(link_to_p1=links_to, link_to_p3=links_to, link_to_p5=links_to, link_to_p7=links_to, link_severed_to_p1=severe, link_severed_to_p3=severe, link_severed_to_p5=severe, link_severed_to_p7=severe, ), check_html=False) if self.participant.finished_rounds == True: yield BlockEnd elif self.player.id_in_group % 2 != 0: yield RedChooses, dict(help_others=help_or_trade_bot) yield Results if self.participant.finished_rounds == True: yield BlockEnd elif test_case == 1: # This batch-tests with players making the same decisions as defined in the variables above. links_to = 1 severe = 1 # (0,1) if self.session.config['treatment'] == 0 or self.session.config['treatment'] == 1: help_or_trade_bot = 0 # (0,1) elif self.session.config['treatment'] == 2: help_or_trade_bot = 2 # (0,1,2) if self.participant.finished_rounds == False: print("ROUND NUMBER IN BOTS", self.round_number) if self.round_number % 2 != 0: if self.player.id_in_group % 2 != 0: # for blue players yield Results yield Submission(BlueChooses, dict(link_to_p2=links_to, link_to_p4=links_to, link_to_p6=links_to, link_to_p8=links_to, link_severed_to_p2=severe, link_severed_to_p4=severe, link_severed_to_p6=severe, link_severed_to_p8=severe, ), check_html=False) if self.participant.finished_rounds == True: yield BlockEnd elif self.player.id_in_group % 2 == 0: yield RedChooses, dict(help_others=help_or_trade_bot) yield Results if self.participant.finished_rounds == True: yield BlockEnd elif self.round_number % 2 == 0: if self.player.id_in_group % 2 == 0: # for blue players yield Results yield Submission(BlueChooses, dict(link_to_p1=links_to, link_to_p3=links_to, link_to_p5=links_to, link_to_p7=links_to, link_severed_to_p1=severe, link_severed_to_p3=severe, link_severed_to_p5=severe, link_severed_to_p7=severe, ), check_html=False) if self.participant.finished_rounds == True: yield BlockEnd elif self.player.id_in_group % 2 != 0: yield RedChooses, dict(help_others=help_or_trade_bot) yield Results if self.participant.finished_rounds == True: yield BlockEnd