from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) class Constants(BaseConstants): name_in_url = 'pg1' #ここで一組何人か決める players_per_group = 4 #ラウンド数 num_rounds = 5 instructions_template = 'pg1/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): def cal_point(self): # プレイヤーの入力した値を全部合計して平均を出してそれを利得にする. players = self.get_players() # players = [P1,P2,P3,P4] player_num = len(players) total_contribution = 0 for player in players: # 全員の貢献の計算 total_contribution += player.contribution # 所持金の計算 player.shojikin -= player.contribution total_contribution *= 2 avg = round(total_contribution / player_num) for player in players: player.point = avg player.ritoku = player.shojikin + player.point class Player(BasePlayer): contribution = models. IntegerField(label='') point = models.IntegerField() ritoku = models.IntegerField() shojikin = models.IntegerField(initial=1000)