from otree.api import * c = cu doc = 'じゃんけん\u3000コンピューターと対決' class C(BaseConstants): NAME_IN_URL = 'PRSvsPC' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): session = subsession.session for p in subsession.get_players(): import random p.Choice_PC = random.randint(1,3) class Group(BaseGroup): pass class Player(BasePlayer): Choice = models.IntegerField(choices=[[1, 'グー'], [2, 'チョキ'], [3, 'パー']]) Choice_PC = models.IntegerField() Win = models.IntegerField() def win_lose(player: Player): player.Win = 1 class Decision(Page): form_model = 'player' form_fields = ['Choice'] @staticmethod def before_next_page(player: Player, timeout_happened): win_lose(player) class Result(Page): form_model = 'player' page_sequence = [Decision, Result]