from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random, itertools author = 'EdK' doc = """ Chat """ class Constants(BaseConstants): name_in_url = 'chat' players_per_group = 3 num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): treatmentfirst = random.choice([1, 2]) if (treatmentfirst % 2) == 0: communication = itertools.cycle([True, False]) if (treatmentfirst % 2) == 1: communication = itertools.cycle([False, True]) for g in self.get_groups(): p1 = g.get_player_by_id(1) p2 = g.get_player_by_id(2) p3 = g.get_player_by_id(3) p1.participant.vars['communication'] = p2.participant.vars['communication'] = p3.participant.vars['communication'] = next(communication) g.communication = p1.participant.vars['communication'] class Group(BaseGroup): communication = models.BooleanField() class Player(BasePlayer): pass