from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'groups_roles' players_per_group = 2 num_rounds = 8 initial_endowment = c(10) # SULLA BASE DELLE LEZIONI DI PLONER, CREO UNA SESSIONE IN CUI PER I PRIMI 4 ROUND # HO IL SET UP CT/CM E PER I SECONDI 4 ROUND HO VT/CM import random class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: self.group_randomly() print(self.get_group_matrix()) for g in self.get_groups(): for p in g.get_players(): if p.id_in_group % 2 == 0: p.participant.vars['type'] = 'BLUE' else: p.participant.vars['type'] = 'GREEN' p.type = p.participant.vars['type'] else: if self.round_number <= 4: self.group_like_round(1) else: self.group_like_round(1) rdm = random.randint(0, 1) print(rdm) for g in self.get_groups(): for p in g.get_players(): if rdm == 1: # this way we randomize role accordin to id in group if p.id_in_group % 2 == 0: p.participant.vars['type'] = 'BLUE' else: p.participant.vars['type'] = 'GREEN' p.type = p.participant.vars['type'] else: if p.id_in_group % 2 == 0: p.participant.vars['type'] = 'GREEN' else: p.participant.vars['type'] = 'BLUE' p.type = p.participant.vars['type'] for p in self.get_players(): if p.participant.vars['type'] == 'BLUE': p.participant.vars['additional'] = c(2) else: p.participant.vars['additional'] = c(-2) p.additional_endow = p.participant.vars['additional'] p.total_endow = p.additional_endow + Constants.initial_endowment class Group(BaseGroup): pass class Player(BasePlayer): type = models.StringField() additional_endow = models.CurrencyField() total_endow = models.CurrencyField()