from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Mizuno' doc = """ """ class Constants(BaseConstants): name_in_url = 'iwg' players_per_group = 4 #グループ人数 (何人でもOK) num_rounds = 16 #ラウンド数 (4の倍数) years = num_rounds//4 initial = c(800) #元手 proper = c(80) #適正処理にかかるコスト cost = c(40) #年末の生産にかかるコスト punishment_endowment = c(40) #監視にかかるコスト punishment = c(200) #罰の大きさ class Subsession(BaseSubsession): pass class Group(BaseGroup): group_inspection = models.CurrencyField() group_ild = models.IntegerField() group_cost = models.CurrencyField() group_detection = models.IntegerField() def season(self): inspections = [p.inspection for p in self.get_players()] self.group_inspection = sum(inspections) for p in self.get_players(): if p.toxicgomi == c(0) and p.gomi == 1: p.ild = 1 else: p.ild = 0 ilds = [p.ild for p in self.get_players()] self.group_ild = sum(ilds) if sum(inspections) >= Constants.punishment_endowment: self.group_inspection = Constants.punishment self.group_detection = 0 else: self.group_inspection = c(0) self.group_detection = self.group_ild self.group_cost = self.group_detection * Constants.cost for p in self.get_players(): if p.toxicgomi == c(0) and p.gomi == 1: p.individual_punishment = self.group_inspection else: p.individual_punishment = c(0) p.payoff = p.individual_punishment + p.toxicgomi + p.normal + p.inspection class Player(BasePlayer): gomi = models.IntegerField() individual_punishment = models.CurrencyField() ild = models.IntegerField() def set_gomi(self): self.gomi = random.choice([0, 0, 0, 1]) toxicgomi = models.CurrencyField( choices=[ [Constants.proper,'お金を払って適正処理する'], [c(0), '無料で不法投棄する'] ], label="有害ごみをどのように処理しますか?", widget = widgets.RadioSelect ) normal = models.CurrencyField( choices=[ [c(0), '処理する'] ], label="普通ごみを処理してください", widget=widgets.RadioSelect ) inspection = models.CurrencyField( choices=[ [Constants.punishment_endowment, '監視する (お金がかかります)'], [c(0), '監視しない'] ], label="監視しますか?", widget=widgets.RadioSelect )