from otree.api import * import random from otree.models import subsession doc = """ This is a standard 2-player trust game where the amount sent by player 1 gets tripled. The trust game was first proposed by Berg, Dickhaut, and McCabe (1995) . """ class Constants(BaseConstants): name_in_url = 'game' players_per_group = None num_rounds = 6 instructions_template = 'regret/instructions.html' money = cu(1000) class Subsession(BaseSubsession): # money = cu(1000) pass class Group(BaseGroup): pass class Player(BasePlayer): treatment = models.BooleanField() card = models.BooleanField( choices=[ [True, 'カード1'], [False, 'カード2'], ], widget=widgets.RadioSelect ) yours = models.FloatField() other = models.FloatField() points = models.CurrencyField() # FANCTION def creating_session(s: Subsession): for p in s.get_players(): p.treatment = random.choice([True, False]) def card_list(p: Player): cards = [i / 10 for i in random.sample(range(10, 35, 5), k=2)] p.yours, p.other = cards def set_points(p: Player, yours): p.points = Constants.money * yours # PAGES class Card(Page): form_model = 'player' form_fields = ['card'] class BackSide(Page): def vars_for_template(p: Player): card_list(p) set_points(p, p.yours) return dict( treatment = p.in_round(1).treatment, yours = p.yours, other = p.other, points = p.points ) page_sequence = [Card, BackSide]