from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random #doc = """人々がコンコルド効果に陥らず合理的判断をするために効果的な解決策の実験""" class Constants(BaseConstants): name_in_url = 'sunkcost_fallacy0' players_per_group = None num_rounds = 10 instructions_template = 'sunkcost_fallacy0/instructions.html' investment = 100 class Subsession(BaseSubsession): success = models.IntegerField(min=1, max=10) def creating_session(self): import random random.seed(4) #乱数シードを4に固定 self.success = random.randint(1,10) if self.success == self.round_number: for p in self.get_players(): price = 1500 p.price = round(price, 0) else: for p in self.get_players(): p.price = 0 class Group(BaseGroup): def set_scores(self): for player in self.get_players(): player.task_1_score = 0 if 'task_1_score' in player.participant.vars: player.task_1_score = player.participant.vars['task_1_score'] class Player(BasePlayer): investment = models.IntegerField() price = models.IntegerField(min=0, max=1500) bop = models.IntegerField() task_1_score = models.IntegerField() fund = models.IntegerField() expense0 = models.IntegerField() stop = models.IntegerField() development_investment = models.BooleanField( choices=[[0, '投資する'], [1, '断念する']], widget=widgets.RadioSelect ) def capital(self): if self.task_1_score >= 1 : self.fund = 1000 elif self.task_1_score >= 60: self.fund = 1500 else: self.fund = 0 def balance_of_payments(self): self.expense0 = 0 - Constants.investment * self.round_number self.fund += self.expense0 self.bop = self.price + self.fund self.stop = self.bop + Constants.investment def set_payoffs(self): self.participant.vars['fund'] = int(self.fund) self.participant.vars['expense0'] = int(self.expense0)