#1 by Ally
Hello, I know this was somewhat addressed in a previous forum post, but I was hoping for a bit more guidance as this function is not working for me. I am trying to match participants in groups of 2, and each round they are matched with a participant they have not matched with before. I have tried setting the group matrix and the group by arrival time method but I am stumped. Thanks for your help, Ally
#2 by dimdub34
Hi, The code below is for version 3.x of oTree but it can easily be modified to fit version 5. --------------------------------------------- pairs = None class Constants(BaseConstants): name_in_url = 'test' players_per_group = None class Subsession(BaseSubsession): def creating_session(self): global pairs if self.round_number == 1: nb_participants = len(self.get_players()) left_players = [p for p in self.get_players()[: nb_participants // 2]] right_players = [p for p in self.get_players()[nb_participants // 2:]] pairs = self.get_pairs(left_players, right_players) self.set_group_matrix(next(pairs)) def get_pairs(self, left_players, right_players): left = [p.id_in_subsession for p in left_players] right = [p.id_in_subsession for p in right_players] while True: yield list(map(list, zip(left, right))) right.append(left.pop()) left.insert(1, right.pop(0)) ------------------- Best Dimitri