Player make decision based on the value of id number of his two subsequent followers

142 views
Skip to first unread message

Flora T

unread,
Oct 9, 2021, 10:45:35 PM10/9/21
to oTree help & discussion
Hi!

I am having a hard time trying to define the payoff of players based on some user entry and I appreciate if I can get some help on this:

1. For all the players in the group (p1, p2.....p20) I generate a random id_in_group for them so they can be a sequence of integers from 1-20 randomly. So for (p1, p2.....p20) they can have an id_in_group as one of them
1) [10, 7, 1, 13, 16, 8, 3, 5, 11, 2, 6, 15, 12, 4, 14, 9]
2) [2, 12, 8, 16, 14, 4, 11, 3, 10, 1, 6, 7, 5, 9, 13, 15]
#Code:
subsession.group_randomly()
print(subsession.group_randomly)

2. I define an integer field for each player to make a decision of under the four scenerios
1) Allocate some money between two participants who both has a participant id>10 : morethanten11,morethanten12
2) Allocate some money between two participants who both has a participant id<10:lessthanten21,lessthanten22
3) Allocate some money between two participants one >=10 and one <10:morethanten31,lessthanten32

3. The first number in the sequence will be the ID number of the person who allocates to the second and third IDs. The second ID drawn will allocate to the third and fourth IDs, , and so on. The second to last ID will allocate to the last and first IDs. 

For example, if the sequence is[10, 7, 1, 13, 16, 8, 3, 5, 11, 2, 6, 15, 12, 4, 14, 9]. Then
Payoff of P2(Id in group=7) will be P1's entry of lessthanten21
Payoff of P3(Id in group=1) will be P1's entry lessthanten22

Payoff of P16(Id in group=9) will be P15's entry of lessthanten32
Payoff of P1(Id in group=10) will be P15's entry of morethanten31

4. I m having a hard time of trying to put all my stuff to codes and I have difficulty in how to refer to the entry of the specific player and  refer the int of the the id of the two followings players.I have written the following code but I think they can't work and I don't know how to adjust them.
#Code:
 @staticmethod
    def after_all_players_arrive(player: Player):
        players = group.get_players()
        
        if i=range(len(players)-2)
             if int(players[i+1].id)>10 and int(players[i+2].id)>10
                player[i+1].payoff=player[i].morethanten11
                p1.payoff=player[i].morethanten12
            if int(players[i+1].id)<5 and int(players[i+2].id)>5
                player[i+1].payoff=player[i].lessthanten21
                p1.payoff=player[i].morethanten22
            if int(players[i+1].id)>=10 and int(players[i+2].id)<10
                player[i+1].payoff=player[i].morethanten31
                p1.payoff=player[i].lessthanten32
            if int(players[i+1].id)<10 and int(players[i+2].id)>=10
                player[i+1].payoff=player[i].lessthanten31
                p1.payoff=player[i].morethanten32
        elif i in range(len(players)-2):
            if i>=1 and i<range(len(players)-2)and int(players[i+1].id)>10 and int(players[i+2].id)>10
                player[i+1].payoff=player[i].morethanten11
                player[i+2].payoff=player[i].morethanten12
            if i>=1  and i<range(len(players)-2) and i<range(len(players)-2) and int(players[i+1].id)<5 and int(players[i+2].id)>5
                player[i+1].payoff=player[i].lessthanten21
                player[i+2].payoff=player[i].morethanten22
            else i>=1  and int(players[i+1].id)>=10 and int(players[i+2].id)<10
                player[i+1].payoff=player[i].morethanten31
                player[i+2].payoff=player[i].lessthanten32

Thanks for the feedback!

Daniel Frey

unread,
Oct 12, 2021, 7:39:01 AM10/12/21
to oTree help & discussion
The first point I see, is that after_all_players_arrive should be a group-function, not a player-function:
  def after_all_players_arrive(group: Group):
    players = group.get_players()

Furthermore: Is there a reason, why you have different scenarios? Do the players know the IDs of the other players and therefore might decide for a different distribution?

I don't quite get your whole if "monster". 
Try to use print-statements to see if the values are saved correctly, start with one condition and add the others afterwards.

I hope that helps!
Daniel

Flora T

unread,
Oct 12, 2021, 1:45:07 PM10/12/21
to oTree help & discussion
Hi Daniel,

Thank you! I will try to start with your suggestion and modify my code.

The reason I have the scenarios is to trying to replicate something done previously to see if there is anything different (although not exactly what I described here but the programming logic is the same and my design is still under some adjustment. I will keep you updated if you are interested if I made some progress on it)

All the best!
Reply all
Reply to author
Forward
0 new messages