oTree Forum >

Different payoffs for two groups with same/different choices

#1 by kkll048 (edited )

Hi everyone,

Sorry for the long post but I really need your help on this. 

I want participants in different groups to have different/same payoffs in each round depending upon their choices.
So, I have two teams playing against each other, let us suppose, each team has two players.

Now, who wins the round depends upon the group's choice. How do I set up different payoffs for participants in two different groups when they have the same choices? or different choices? The payoffs are determined on the group level, meaning, participants in the same team get the same payoffs. In my experiment, we switch participants randomly after some rounds for which the code is ready and set. I need help with setting up payoffs....which is at the end of the code below. 

For example:
Two teams A and B select prices of 20 each.
For team A, the payoff while selecting 20 is 31, and for team B, the payoff while selecting 20 is 29. How do I do this? Also, I need to do this for choices starting from 0 to 49, there's a matrix of payoff and your payoff depends on your choice as well as the other team's choice (if a price between 21 and 49 is selected). If a price below 21 is selected, Team A and Team B's payoffs do not depend on each other's choices, but there are predefined payoffs, which are different and depend on which team you are on.

Also, how can I set up a profit calculator on the screen where subjects can input their choice and assume another team's choice and see what their payoffs could look like based on this payoff matrix? Please look at the attached image for the payoff matrix. 

How my code looks:
 PRICE_MIN = cu(0)
 PRICE_MAX = cu(49)
 COLORS = ['A', 'B']
 class Subsession(BaseSubsession):
    winning_price = models.IntegerField()
 def creating_session(subsession: Subsession):
    session = subsession.session
    if subsession.round_number == 1:
        from random import shuffle

        session = subsession.session
        players_per_group = session.config['players_per_group']
        num_firms = session.config['num_firms']
        num_participants = session.num_participants
        if num_participants != num_firms * players_per_group:
            raise ValueError(f'Number of participants in the session must be {num_firms} * {players_per_group}')

        players = subsession.get_players()
        for p in players:
            p.participant.moved = False

        group_matrix = [players[n: n + players_per_group] for n in range(0, len(players), players_per_group)]

        for n, s in enumerate(subsession.in_rounds(1, C.ROUND_NUMBER_SWITCH - 1)):
            # set group matrix for all rounds up to the switch round (excluded)
            if n == 0:
                for i, g in enumerate(s.get_groups()):
                    color = C.COLORS[i]
                    g.color = color
                    for p in g.get_players():
                        p.participant.uuid = f'{color} {p.id_in_group}'
                for i, g in enumerate(s.get_groups()):
                    g.color = C.COLORS[i]

        # From each original group extract a randomly selected employee using pop() with a random index
        from random import randint
        employees_to_switch = [g.pop(randint(0, players_per_group - 1)) for g in group_matrix]
        for e in employees_to_switch:
            e.participant.moved = True
            e.moved = True
            e.group.moved_player_id = e.id_in_group

        # Change the list order of the employees to re-assign

        for n, p in enumerate(employees_to_switch):
            # Reassign each employee to the new group

        for s in subsession.in_rounds(C.ROUND_NUMBER_SWITCH, C.NUM_ROUNDS):
            # Set group matrix for all rounds from the switch round (included)

            for i, g in enumerate(s.get_groups()):
                g.color = C.COLORS[i]
def set_payoffs(subsession: Subsession):
    session = subsession.session
    groups = subsession.get_groups()
    for g in groups:

    winning_price = min([g.price for g in groups])
    subsession.winning_price = winning_price
    num_winners = len([g for g in groups if g.price == winning_price])
    for g in groups:
        g.win = g.price == winning_price
        if g.win:
            for p in g.get_players():
                if g.price in [0, 1]:
                    p.payoff = 0
                elif g.price == 2:
                    p.payoff = 1
                elif g.price == 3:
                    p.payoff = 2
                elif g.price == 4:
                    p.payoff = 3
I need help setting payoffs. I'm sure there is a better way to do this. As of now, my code doesn't give different payoffs for two different teams. However, what I want is different payoffs for Team A and B, when their choices are between 0 and 21; and payoffs based on the matrix in the attached image when the choices are between 21 and 49.

Thank you for going through all this and for your help in advance.

Write a reply

Set forum username