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 = 'jikken2' players_per_group = 5 num_rounds = 12 instructions_template = 'jikken2/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 + p.in_round(9).payoff + p.in_round(10).payoff + p.in_round(11).payoff + p.in_round(12).payoff) if p.eating == 300: p.shuppi = 2000 if p.round_number == 1: p.shuppi2 = int(p.shuppi*1.12) elif p.round_number == 2: p.shuppi2 = int(p.shuppi*1.1) elif p.round_number == 3: p.shuppi2 = int(p.shuppi*1.1) elif p.round_number == 4: p.shuppi2 = int(p.shuppi*1.08) elif p.round_number == 5: p.shuppi2 = int(p.shuppi*1.15) elif p.round_number == 6: p.shuppi2 = int(p.shuppi*1.1) elif p.round_number == 7: p.shuppi2 = int(p.shuppi*1.1) elif p.round_number == 8: p.shuppi2 = int(p.shuppi*1.05) elif p.round_number == 9: p.shuppi2 = int(p.shuppi*1.17) elif p.round_number == 10: p.shuppi2 = int(p.shuppi*1.1) elif p.round_number == 11: p.shuppi2 = int(p.shuppi*1.1) elif p.round_number == 12: p.shuppi2 = int(p.shuppi*1.03) elif p.eating == 100: p.shuppi = 500 p.shuppi2 = int(p.shuppi*1.1) elif p.eating ==0: p.shuppi = 0 p.shuppi2 = 0 p.total_shojikin = (19200 - 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 - p.in_round(9).shuppi2 - p.in_round(10).shuppi2 - p.in_round(11).shuppi2 - p.in_round(12).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 == 12: pass else: p.in_round(p.round_number+1).shojikin = p.total_shojikin if p.eating == 0: p.cost = '0' elif p.eating == 100: p.cost = (str(p.shuppi) + ' × ' + str(1.1) + ' = ' + str(p.shuppi2)) elif p.eating == 300: if p.round_number == 1: tax = 1.12 elif p.round_number == 2: tax = 1.1 elif p.round_number == 3: tax = 1.1 elif p.round_number == 4: tax = 1.08 elif p.round_number == 5: tax = 1.15 elif p.round_number == 6: tax = 1.1 elif p.round_number == 7: tax = 1.1 elif p.round_number == 8: tax = 1.05 elif p.round_number == 9: tax = 1.17 elif p.round_number == 10: tax = 1.1 elif p.round_number == 11: tax = 1.1 elif p.round_number == 12: tax = 1.03 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=19200) cost = models.StringField() check2 = models.IntegerField( choices=[[1, '理解した']], label='ルールについて完全に理解しましたか?', widget= widgets.RadioSelect, ) def other_player(self): return self.get_others_in_group()[0]