oTree Forum >

Problem with payoff of players in group treatment

#1 by Anwesha

Hello there,

So, I have finished coding the group treatment. Things seem to be working well except the payoff part. Well, a part of it is working well. But not entirely. So each group has two players and each one of then can select two assets:  A and B. If both players select asset A or asset B and a random number gets generated, they get paid accordingly. However, if one player selects A and the other B and the same random number gets generated, the player who selected asset A gets paid for that asset and the player who selected asset B, gets paid for asset B. This is where things are not working. My code is mentioned below. Could you kindly advise me on this? The ultimate decision variable is decision2.
class C(BaseConstants):
    NAME_IN_URL = 'group_esg'
    PLAYERS_PER_GROUP = 2
    NUM_ROUNDS = 1
    ENDOWMENT_PER_PLAYER = 100
    payment_assetA = 110
    payment_assetB = 115
    payment_otherwise = 30
    
 class Player(BasePlayer):
    decision1 = models.BooleanField(
        label="Please make a selection between Asset A and Asset B",
        choices=[
            [True, "Asset A"],
            [False, "Asset B"],
        ],
        widget=widgets.RadioSelect,
    )
    time1 = models.FloatField()
    decision2 = models.BooleanField(
        label="Please make a selection between Asset A and Asset B",
        choices=[
            [True, "Asset A"],
            [False, "Asset B"],
        ],
        widget=widgets.RadioSelect,
    )
    time2 = models.FloatField()
    
class Results(Page):
    @staticmethod
    def vars_for_template(player: Player):
        pchoice = np.random.random()
        if pchoice <= 0.5:
            Group.get_payoff = 1
        else:
            Group.get_payoff = 0
        if player.decision2 == True:
            player.payoff += C.payment_assetA * Group.get_payoff
        if player.decision2 == False:
            player.payoff += C.payment_assetB * Group.get_payoff
        if Group.get_payoff == 0:
            player.payoff += C.payment_otherwise
        return dict(
            earning=format(Decimal(player.payoff) / Decimal(10), '.2f')
        )

#2 by MouliModak

Hi,

I think player.payoff does not allow +=. It's a round-specific variable.

I hope this helps.

Best wishes,
Mouli Modak

#3 by Anwesha

Thank you.

Write a reply

Set forum username