from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) doc = """ demoではやりやすいように2人一組になっているが、実際やるときは便宜上5人一組するか。 全員が外食をすると、利得が50になるから。 """ class Constants(BaseConstants): name_in_url = 'jikken' players_per_group = 5 num_rounds = 8 instructions_template = 'jikken/instructions.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): def set_payoffs(self): players = self.get_players() tax = 1.1 gaishoku_count = -1 for p in players: if p.eating == 300: gaishoku_count += 1 for p in players: if p.eating == 300: if gaishoku_count == 0: p.payoff = 300 elif gaishoku_count == 1: p.payoff = 262 elif gaishoku_count == 2: p.payoff = 207 elif gaishoku_count == 3: p.payoff = 143 elif gaishoku_count == 4: p.payoff = 50 else: p.payoff = p.eating p.total_payoff = (p.in_round(1).payoff + p.in_round(2).payoff + p.in_round(3).payoff + p.in_round(4).payoff + p.in_round(5).payoff + p.in_round(6).payoff + p.in_round(7).payoff + p.in_round(8).payoff) if p.eating == 300: p.shuppi = 2000 elif p.eating == 100: p.shuppi = 500 elif p.eating ==0: p.shuppi = 0 p.shuppi2 = int(p.shuppi * tax) p.total_shojikin = (12800 - p.in_round(1).shuppi2 - p.in_round(2).shuppi2 - p.in_round(3).shuppi2 - p.in_round(4).shuppi2 - p.in_round(5).shuppi2 - p.in_round(6).shuppi2 - p.in_round(7).shuppi2 - p.in_round(8).shuppi2) if p.total_shojikin <0: p.final = p.total_payoff + p.total_shojikin//5 else : p.final = p.total_payoff + p.total_shojikin//15 if p.round_number == 8: pass else: p.in_round(p.round_number+1).shojikin = p.total_shojikin if p.eating == 0: p.cost = '0' else: p.cost = (str(p.shuppi) + ' × ' + str(tax) + ' = ' + str(p.shuppi2)) class Player(BasePlayer): eating = models.CurrencyField( choices=[[0, '食べない'],[100, '自炊'], [300, '外食'] ], label='今夜、私がいただくのは?', widget=widgets.RadioSelect, ) total_payoff = models.CurrencyField() total_shojikin = models.IntegerField() shuppi = models.IntegerField(initial=0) shuppi2 = models.IntegerField(initial=0) final = models.CurrencyField(initial=0) shojikin = models.IntegerField(initial=12800) cost = models.StringField() check1 = models.IntegerField( choices=[[1, '理解した']], label='', widget= widgets.RadioSelect, ) def other_player(self): return self.get_others_in_group()[0]