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 = 'CEO2' players_per_group = 4 num_rounds = 10 instructions_template = 'CEO2/instructions.html' # Initial amount allocated to each player contract1 = 1 contract2 = 2 company1_owner_id = 2 company1_manager_id = 1 company2_owner_id = 4 company2_manager_id = 3 production1 = 60 production2 = 70 production3 = 80 production4 = 90 # 利得計算用定数 a = 240 c = 30 x = 0.02 y = 0.01 class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_ritoku(self): # 企業1の所有者 company1_owner = self.get_player_by_id(Constants.company1_owner_id) # 企業1の経営者 company1_manager = self.get_player_by_id(Constants.company1_manager_id) # 企業2の所有者 company2_owner = self.get_player_by_id(Constants.company2_owner_id) # 企業2の経営者 company2_manager = self.get_player_by_id(Constants.company2_manager_id) if company1_owner.contract == 1 and company2_owner.contract == 1: # 企業1の所有者と経営者の利得 total_production = company1_manager.production + company2_manager.production p = Constants.a - total_production profit1 = p * company1_manager.production - Constants.c * company1_manager.production company1_owner.ritoku = int(profit1) company1_manager.ritoku = int(profit1 * Constants.x) # 企業2の所有者と経営者の利得 profit2 = p * company2_manager.production - Constants.c * company2_manager.production company2_owner.ritoku = int(profit2) company2_manager.ritoku = int(profit2 * Constants.x) elif company1_owner.contract == 1 and company2_owner.contract == 2: # 企業1の所有者と経営者の利得 total_production = company1_manager.production + company2_manager.production p = Constants.a - total_production profit1 = p * company1_manager.production - Constants.c * company1_manager.production company1_owner.ritoku = int(profit1) company1_manager.ritoku = int(profit1 * Constants.x) # 企業2の所有者と経営者の利得 sales2 = p * company2_manager.production profit2 = p * company2_manager.production - Constants.c * company2_manager.production company2_owner.ritoku = int(profit2) company2_manager.ritoku = int(sales2 * Constants.y) elif company1_owner.contract == 2 and company2_owner.contract == 1: # 企業1の所有者と経営者の利得 total_production = company1_manager.production + company2_manager.production p = Constants.a - total_production sales1 = p * company1_manager.production profit1 = p * company1_manager.production - Constants.c * company1_manager.production company1_owner.ritoku = int(profit1) company1_manager.ritoku = int(sales1 *Constants.y) #企業2の所有者と経営者の利得 profit2 = p * company2_manager.production - Constants.c * company2_manager.production company2_owner.ritoku = int(profit2) company2_manager.ritoku = int(profit2 * Constants.x) elif company1_owner.contract == 2 and company2_owner.contract == 2: # 企業1の所有者と経営者の利得 total_production = company1_manager.production + company2_manager.production p = Constants.a - total_production sales1 = p * company1_manager.production profit1 = p * company1_manager.production - Constants.c * company1_manager.production company1_owner.ritoku = int (profit1) company1_manager.ritoku = int (sales1 *Constants.y) #企業2の所有者と経営者の利得 sales2 = p * company2_manager.production profit2 = p * company2_manager.production - Constants.c * company2_manager.production company2_owner.ritoku = int(profit2) company2_manager.ritoku = int(sales2 * Constants.y) #所有者の利得表算出用関数 def cal_table00(self): yoko0_lst = [Constants.production1,Constants.production2,Constants.production3,Constants.production4] tate0_lst = [Constants.production1,Constants.production2,Constants.production3,Constants.production4] profit_lst = [] for tate in tate0_lst: lst = [] for yoko in yoko0_lst: total_production = yoko + tate p = Constants.a - total_production profit = p * tate - Constants.c * tate lst.append(int(profit)) profit_lst.append(lst) return profit_lst #企業全体の売上高表算出用関数 def cal_table01(self): yoko0_lst = [Constants.production1,Constants.production2,Constants.production3,Constants.production4] tate0_lst = [Constants.production1,Constants.production2,Constants.production3,Constants.production4] sales_lst = [] for tate in tate0_lst: lst = [] for yoko in yoko0_lst: total_production = yoko + tate p = Constants.a - total_production sales = p * tate lst.append(int(sales)) sales_lst.append(lst) return sales_lst #(自社,ライバル)=(契約1,契約1),(契約1,契約2)の利得表算出用関数 def cal_table11(self): yoko0_lst = [Constants.production1,Constants.production2,Constants.production3,Constants.production4] tate0_lst = [Constants.production1,Constants.production2,Constants.production3,Constants.production4] ritoku_lst = [] for tate in tate0_lst: lst = [] for yoko in yoko0_lst: total_production = yoko + tate p = Constants.a - total_production profit = p * tate - Constants.c * tate ritoku = profit * Constants.x lst.append(int(ritoku)) ritoku_lst.append(lst) return ritoku_lst #(自社,ライバル)=(契約2,契約2),(契約2,契約1)の利得表算出用関数 def cal_table22(self): yoko0_lst = [Constants.production1,Constants.production2,Constants.production3,Constants.production4] tate0_lst = [Constants.production1,Constants.production2,Constants.production3,Constants.production4] ritoku_lst = [] for tate in tate0_lst: lst = [] for yoko in yoko0_lst: total_production = yoko + tate p = Constants.a - total_production profit = p * tate ritoku = profit * Constants.y lst.append(int(ritoku)) ritoku_lst.append(lst) return ritoku_lst class Player(BasePlayer): contract = models.IntegerField( choices=[[1,'契約1'],[2,'契約2']], label='', widget=widgets.RadioSelectHorizontal, ) production = models.IntegerField( choices=[Constants.production1,Constants.production2,Constants.production3,Constants.production4], label='', widget=widgets.RadioSelectHorizontal, ) ritoku = models.IntegerField()