from otree.api import Currency as c, currency_range import random from ._builtin import Page, WaitPage from .models import Constants class Instruction(Page): def is_displayed(self): return self.player.id_in_group == 1 class Choice(Page): def is_displayed(self): return self.player.id_in_group == 1 form_model = "group" form_fields = ["Game_choice"] class WTP(Page): def is_displayed(self): return self.player.id_in_group == 1 form_model = "group" form_fields = ["WTP_choice"] class Waitforall(WaitPage): # wait_for_all_groups = True title_text = " " body_text = "The row players are making decisions. Please wait patiently." def after_all_players_arrive(self): self.group.get_rand() self.group.get_rand_exodraw() self.group.get_rand_endodraw() TypeA_list = [] TypeB_list = [] for p in self.group.get_players(): if p.id_in_group == 1: TypeA_list.append(p) else: TypeB_list.append(p) print(TypeA_list) print(TypeB_list) for p in TypeA_list: if p.group.rand < 3: p.elicitation_pay = 0 if p.group.rand_exodraw == 1: p.group.realized = 0 else: p.group.realized = 1 else: if p.group.rand_endodraw <= p.group.WTP_choice: p.group.realized = p.group.Game_choice p.elicitation_pay = 0 else: p.group.realized = 1 - p.group.Game_choice p.elicitation_pay = p.group.rand_endodraw p.participant.vars['realized'] = p.group.realized # print(p.group.realized) for p in TypeB_list: group = p.get_others_in_group() partner = group[0] p.elicitation_pay = 0 p.participant.vars['realized'] = partner.group.realized print(p.group.realized) class Results(Page): def vars_for_template(self): self.participant.payoff += self.player.elicitation_pay page_sequence = [Instruction, Choice, WTP, Waitforall, Results]