oTree Forum >

set_group_matrix() using a variable

#1 by FEDx

Hi everybody,
is it possible to do something like:

def creating_session(subsession: Subsession):
        session = subsession

        x_players = [p for p in players if p.participant.vars['xy'] == 'x']
        y_players = [p for p in players if p.participant.vars['xy'] == 'y']

        print(f"Number of x players: {len(x_players)}")
        print(f"Number of y players: {len(y_players)}")

        matrix = []
        while len(x_players) >= 2 and len(y_players) >= 2:
            group = x_players[:2] + y_players[:2]
            matrix.append(group)

            # Remove grouped players
            x_players = x_players[2:]
            y_players = y_players[2:]


        # Assign the group matrix
        self.set_group_matrix(matrix)

 Note: p.participant.vars['xy'] is set-up by the player entering a number in the first app of the experiment.
 
 Thanks a lot

Write a reply

Set forum username