oTree Forum >

re-matching with a stranger and a new gender in each round

#1 by Sarah

Hello all,
I have four rounds in one of my apps and I want participants to be matched with a stranger in each round. This is my code and it works very well. 
def creating_session(subsession: Subsession):
    if subsession.round_number == 1:
        session = subsession.session
        players = subsession.get_players()
        even_players = [p for p in players if is_even(p.id_in_group)]
        odd_players = [p for p in players if not is_even(p.id_in_group)]
        subsession.set_group_matrix([[i, j] for i, j in zip(even_players, odd_players)])
        print(subsession.get_group_matrix())
    else:
        subsession.group_like_round(subsession.round_number - 1)
        group_matrix = subsession.get_group_matrix()
        print("Next Group:")
        print(group_matrix)
        even_players = Extract(group_matrix)
        odd_players = Extract2(group_matrix)
        odd_players = right_rotate(odd_players)

        subsession.set_group_matrix([[i, j] for i, j in zip(even_players, odd_players)])
        print(subsession.get_group_matrix())

I also want participants to be matched with a new gender in each round. For example, regardless of the participant's gender, they match with the order of "Female, Male, Female, and Male" in each round. 
So, I'd like to have both matching processes based on the even or odd players and the genders. Could anyone help me with that? 
Thank you in advance.

#2 by lucas

Can you roughly write out an algorithm by hand to accomplish what you want, determine your algorithm's limitations (for example, your current code above will only make n/2 unique matches despite n-1 unique matches being possible given n subjects), decide if these limitations are acceptable? If you get stuck in this process, we can probably nudge you along.

BTW:

a) Line 3 `session = subsession.session` is unneeded.

b) I can assume what Extract and Extract2 and right_rotate do, but you should include their definitions to facilitate an answer.

Write a reply

Set forum username