Hi guys,
Today I am facing a problem using a random mechanism to determin the roles. I have 5 players in each game for 10 rounds, where I need to keep the role fixed in all rounds.
The following is what i did, firstly I randomly get a list of numbers, the player get the max number will be the "first mover", the rest 4 players will be the " regular mover. I set everything on the "player" page.
def roles_setting(player):
import random
random_value = random.sample(range(0, 10), 5)
if player.random_value == max(random_value):
player.roles = 'first mover'
else:
player.roles = 'regular mover'
roles = models.StringField()
The error message shows: player.roles is None. Accessing a null field is generally considered an error.
SO did I set it in a wrong way? I don't think it should be defined in the "group" page or "subsession" page. Also where should I import random?
My second question is, I also set certain pages shown only to first mover, then I think this method is also incorrect.
def is_displayed(player):
return player.roles == "first mover"
I think I did something wrong but don't know how to fix it. Thank you for your time in advance.
Shaorong