from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random author = 'Siyu' doc = """ belief formation exogenous """ class Constants(BaseConstants): name_in_url = 'b_belief_formation_Exo' players_per_group = None num_rounds = 16 total_tile = 20 instructions_template = 'b_belief_formation_Exo/instructions.html' class Subsession(BaseSubsession): def creating_session(self): import random paying_round = random.randint(1, Constants.num_rounds) self.session.vars['paying_round'] = paying_round print('set the paying round to', paying_round) class Group(BaseGroup): pass class Player(BasePlayer): computer_tile = models.IntegerField() x = models.IntegerField() game_payoff = models.CurrencyField() com_tile_color = models.IntegerField( choices=[ [2, 'Green_Square'], [1, 'Green_Circular'], [0, 'Yellow_Circular'], ] ) hat_color = models.IntegerField( choices=[ [1, 'Green'], [0, 'Yellow'], ] ) look_choice = models.IntegerField( choices=[ [1, 'Look'], [0, 'Not Look'], ] ) def random_numbers(self): self.computer_tile = random.randint(1, Constants.total_tile) self.x = 20 + random.randint(0, 2) * 30 print('computer selects tiles', self.computer_tile) print('payoff x is', self.x) def set_payoff(self): if self.computer_tile <= 10: self.com_tile_color = 2 elif self.computer_tile <= 15: self.com_tile_color = 1 else: self.com_tile_color = 0 print('tile color is', self.com_tile_color) if self.look_choice == 0: self.hat_color = 0 elif self.com_tile_color == 0: self.hat_color = 0 else: self.hat_color = 1 print('hat color is', self.hat_color) if self.hat_color == 0 and self.com_tile_color < 2: self.payoff = 100 elif self.hat_color == 1 and self.com_tile_color == 2: self.payoff = self.x else: self.payoff = 0 self.participant.vars['paying_r'] = self.session.vars['paying_round'] if self.subsession.round_number == self.session.vars['paying_round']: self.participant.vars['game_payoff'] = self.payoff * 0.1