from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ This is a standard 2-player trust game where the amount sent by player 1 gets tripled. The trust game was first proposed by Berg, Dickhaut, and McCabe (1995) . """ class Constants(BaseConstants): name_in_url = 'team4' players_per_group = 2 num_rounds = 16 instructions_template = 'team4/instructions.html' # Initial amount allocated to each player endowment = 8 multiplier = 1/2 class Subsession(BaseSubsession): def creating_session(self): matrix = self.get_group_matrix() structure_a = [[1,2], [3,4], [5,6], [7,8], [9,10]] structure_b = [[2,1], [4,3], [6,5], [8,7], [10,9]] structure_1 = [[3,2], [5,4], [7,6], [9,8], [1,10]] structure_2 = [[5,2], [7,4], [9,6], [1,8], [3,10]] structure_3 = [[7,2], [9,4], [1,6], [3,8], [5,10]] structure_4 = [[9,2], [1,4], [3,6], [5,8], [7,10]] structure_5 = [[2,3], [4,5], [7,6], [8,9], [10,1]] structure_6 = [[2,5], [4,7], [6,9], [8,1], [10,3]] structure_7 = [[2,7], [4,9], [6,1], [8,3], [10,5]] structure_8 = [[2,9], [4,1], [6,3], [8,5], [10,7]] #グループ固定で「AかBか」はランダム(A,B:4回ずつ) if self.round_number == 1: self.set_group_matrix(structure_a) elif self.round_number == 2: self.set_group_matrix(structure_a) elif self.round_number == 3: self.set_group_matrix(structure_b) elif self.round_number == 4: self.set_group_matrix(structure_a) elif self.round_number == 5: self.set_group_matrix(structure_b) elif self.round_number == 6: self.set_group_matrix(structure_b) elif self.round_number == 7: self.set_group_matrix(structure_b) elif self.round_number == 8: self.set_group_matrix(structure_a) #グループも「AかBか」もランダム(A,B:4回ずつ) elif self.round_number == 9: self.set_group_matrix(structure_1) elif self.round_number == 10: self.set_group_matrix(structure_5) elif self.round_number == 11: self.set_group_matrix(structure_6) elif self.round_number == 12: self.set_group_matrix(structure_2) elif self.round_number == 13: self.set_group_matrix(structure_3) elif self.round_number == 14: self.set_group_matrix(structure_4) elif self.round_number == 15: self.set_group_matrix(structure_7) elif self.round_number == 16: self.set_group_matrix(structure_8) #役割固定で良いなら(前半と後半で1回変わるかもしれない) # if self.round_number == 1: # self.group_randomly() # elif self.round_number <= 8: # self.group_like_round(1) # else: # self.group_randomly(fixed_id_in_group=True) # import random # matrix = self.get_group_matrix() # for row in matrix: # row = random.shuffle(row) # self.set_group_matrix(matrix) class Group(BaseGroup): p1_sent_amount = models.IntegerField( min=0, max=Constants.endowment, doc="""Amount sent by P1""", label="Bさんに何切れのケーキをあげますか?(0から8の整数値):", ) p2_accept = models.StringField( label=".", choices=[['A','受け入れる'],['R','拒否する']], widget=widgets.RadioSelect, ) p2_sent_amount = models.IntegerField( min=0, max=Constants.endowment * Constants.multiplier, doc="""Amount sent back by P2""", label="Aさんに何切れのケーキをあげますか?(0から4の整数値):" ) p1_accept = models.StringField( label=".", choices=[['A','受け入れる'],['R','拒否する']], widget=widgets.RadioSelect, ) def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) if self.p2_accept == 'A': p1.payoff = Constants.endowment - self.p1_sent_amount p2.payoff = self.p1_sent_amount elif self.p2_accept == 'R' and self.p1_accept == 'A': p1.payoff = self.p2_sent_amount p2.payoff = Constants.endowment * Constants.multiplier - self.p2_sent_amount else: p1.payoff = 0 p2.payoff = 0 class Player(BasePlayer): pass