from otree.api import * c = cu doc = '' class Constants(BaseConstants): players_per_group = None num_rounds = 1 name_in_url = 'bret' box_value = cu(1) num_rows = 10 num_cols = 10 box_height = '50px' box_width = '50px' random_payoff = True instructions = True feedback = True results = True dynamic = True time_interval = 1 random = True devils_game = False undoable = True class Subsession(BaseSubsession): pass class Group(BaseGroup): pass def set_payoff(player): session = player.session subsession = player.subsession participant = player.participant import random if player.bomb: player.round_result = c(0) else: player.round_result = player.boxes_collected * Constants.box_value # set payoffs if to round_result of randomly chosen round # randomly determine round to pay on player level if player.subsession.round_number == 1: player.participant.vars['round_to_pay'] = random.randint(1,Constants.num_rounds) if Constants.random_payoff: if player.subsession.round_number == player.participant.vars['round_to_pay']: player.pay_this_round = True player.payoff = player.round_result else: player.pay_this_round = False player.payoff = c(0) # set payoffs to round_result if else: player.payoff = player.round_result class Player(BasePlayer): RiskLevel = models.FloatField(initial=-1) choice1 = models.StringField(choices=[['A彩票', 'A彩票'], ['B彩票', 'B彩票']], label='', widget=widgets.RadioSelectHorizontal) choice2 = models.StringField(choices=[['A彩票', 'A彩票'], ['B彩票', 'B彩票']], label='', widget=widgets.RadioSelectHorizontal) choice3 = models.StringField(choices=[['A彩票', 'A彩票'], ['B彩票', 'B彩票']], label='', widget=widgets.RadioSelectHorizontal) choice4 = models.StringField(choices=[['A彩票', 'A彩票'], ['B彩票', 'B彩票']], label='', widget=widgets.RadioSelectHorizontal) choice5 = models.StringField(choices=[['A彩票', 'A彩票'], ['B彩票', 'B彩票']], label='', widget=widgets.RadioSelectHorizontal) choice6 = models.StringField(choices=[['A彩票', 'A彩票'], ['B彩票', 'B彩票']], label='', widget=widgets.RadioSelectHorizontal) choice7 = models.StringField(choices=[['A彩票', 'A彩票'], ['B彩票', 'B彩票']], label='', widget=widgets.RadioSelectHorizontal) choice8 = models.StringField(choices=[['A彩票', 'A彩票'], ['B彩票', 'B彩票']], label='', widget=widgets.RadioSelectHorizontal) choice9 = models.StringField(choices=[['A彩票', 'A彩票'], ['B彩票', 'B彩票']], label='', widget=widgets.RadioSelectHorizontal) choice10 = models.StringField(choices=[['A彩票', 'A彩票'], ['B彩票', 'B彩票']], label='', widget=widgets.RadioSelectHorizontal) bomb = models.IntegerField() bomb_row = models.IntegerField(min=0) bomb_col = models.IntegerField(min=0) boxes_collected = models.IntegerField() pay_this_round = models.BooleanField() round_result = models.CurrencyField() class Lottery_Choice(Page): form_model = 'player' form_fields = ['choice1', 'choice2', 'choice3', 'choice4', 'choice5', 'choice6', 'choice7', 'choice8', 'choice9', 'choice10'] @staticmethod def before_next_page(player, timeout_happened): participant = player.participant participant.vars['choice5'] = player.choice5 class FinalPage(Page): form_model = 'player' @staticmethod def before_next_page(player, timeout_happened): participant = player.participant player.choice5= participant.vars['choice5'] page_sequence = [Lottery_Choice, FinalPage]