import numpy as np from . import models from ._builtin import Page, WaitPage from .models import Constants import random import numpy as np class Introduction(Page): def is_displayed(self): return self.round_number == 1 class PeriodWaitPage(WaitPage): # bot_personality = random.randint(0, 1) def after_all_players_arrive(self): for player in self.subsession.get_players(): player.loss_probability = player.participant.lossprob_list[self.round_number - 1] player.cost = player.participant.cost_list[self.round_number - 1] player.bot_advice = player.calculate_advice() # if self.bot_personality == 0: # player.bot_advice = player.calculate_advice() # else: # player.bot_advice = player.calculate_random_advice() if player.bot_advice == '冒险': player.bot_advice_number = 1 else: player.bot_advice_number = 2 # self.group.loss_probability = Constants.loss_probabilities_list[self.round_number - 1] # if self.bot_personality == 0: # self.group.bot_advice = self.group.calculate_advice() # else: # self.group.bot_advice = self.group.calculate_random_advice() class BotAdvice(Page): pass class BotAdviceTransparent(Page): def vars_for_template(self): if self.player.risk_result < self.player.cost_result: compare = '小于' else: compare = '大于' # riskresult = 30 - Constants.loss_amount * self.player.loss_probability # costresult = 30 - self.player.cost riskresult = ("%.1f" % self.player.risk_result) return{ 'riskresult':riskresult, 'costresult': self.player.cost_result, 'compare': compare, } class Decision(Page): form_model = models.Player form_fields = ['decision_taken'] def vars_for_template(self): self.player.random_number_generated = round(random.random(), 2) return { 'round_number': self.round_number } # def before_next_page(self): # if self.player.decision_taken =='冒险': # self.decision_number = 1 # else: # self.decision_number = 2 class Results(Page): def vars_for_template(self): self.player.set_payoffs() if self.round_number == Constants.num_rounds: self.player.paying_round = random.randint(1, Constants.num_rounds - 1) # self.player.investment_outcome = random.choice(['Good', 'Bad']) return { 'round_number': self.round_number, 'cost_list': self.player.participant.cost_list, 'loss_list': self.player.participant.lossprob_list, } class Investment(Page): form_model = models.Player form_fields = ['investment_chosen'] def is_displayed(self): return self.round_number == Constants.num_rounds class FinalResultWaitPage(WaitPage): def after_all_players_arrive(self): pass class FinalResult(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): self.player.total_payoffs() self.player.participant.vars['final_payoff']=self.player.final_payoff return { 'payoff': self.player.final_payoff, 'round_pay': self.player.in_round(self.player.paying_round).amount_won_in_round } page_sequence = [ Introduction, PeriodWaitPage, BotAdviceTransparent, Decision, Results, # Investment, FinalResultWaitPage, FinalResult ]