from otree.api import * import random random.seed(3324) doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'human_robot_HH2' players_per_group = 3 num_rounds = 1 participation_fee = cu(10) payment_from_questionnaire = cu(10) listener_payoff = cu(20) def creating_session(subsession): subsession.group_randomly() class Subsession(BaseSubsession): pass class Group(BaseGroup): choice_A = models.IntegerField(choices=[1, 2, 3, 4, 5, 6],) choice_B = models.IntegerField(choices=[[0, '不接收'], [1, '接受'], ]) HH_communication = models.LongStringField() def set_payoffs(group): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) if group.choice_B == 1: p1.payoff = Constants.participation_fee+Constants.payment_from_questionnaire+(60-10*group.choice_A) p2.payoff = Constants.participation_fee+Constants.payment_from_questionnaire+(-10+10*group.choice_A) p3.payoff = Constants.participation_fee + Constants.payment_from_questionnaire + Constants.listener_payoff else: p1.payoff = Constants.participation_fee+Constants.payment_from_questionnaire p2.payoff = Constants.participation_fee + Constants.payment_from_questionnaire p3.payoff = Constants.participation_fee + Constants.payment_from_questionnaire + Constants.listener_payoff class Player(BasePlayer): gender = models.StringField( choices=['男', '女'], widget=widgets.RadioSelectHorizontal() ) age = models.IntegerField() # PAGES class Greetings(Page): pass class Instruction(Page): pass class Achoice(Page): form_model = 'group' form_fields = ['choice_A'] @staticmethod def is_displayed(player): return player.id_in_group == 1 class WaitforA(WaitPage): pass class Bchoice(Page): form_model = 'group' form_fields = ['choice_B', 'HH_communication'] @staticmethod def is_displayed(player): return player.id_in_group == 2 class WaitforB(WaitPage): pass class Feedback(Page): @staticmethod def is_displayed(player): return player.id_in_group == 3 class WaitforConfirm(WaitPage): pass class Questionnaire(Page): form_model = 'player' form_fields = ['gender', 'age'] class ResultsWaitPage(WaitPage): after_all_players_arrive = set_payoffs class Results(Page): pass page_sequence = [ Greetings, Instruction, Achoice, WaitforA, Bchoice, WaitforB, Feedback, WaitforConfirm, Questionnaire, ResultsWaitPage, Results ]