Hi,
I'm trying to program a pyramid like score system for an ARG game and have come up with a problem. When users get into the game they start a new "pyramid" but if one start the game with a referer code from another player they become a child of this user and then kick points up the ladder.
The issue here is not the point calculation, I've gotten that right with some good help from you guys, but if a user gets more point that it parent, they should switch places in the ladder. So that a users parent becomes it's child and so on.
The python code I have now doesnt work proper, and I dont really know why.
def verify_parents(user):
"""
This is a recursive function that checks to see if any of the parents
should bump up because they got more points than its parent.
"""
from rottenetter.accounts.models import get_score
try:
parent = user.parent
except:
return False
else:
# If this players score is greater than its parent
if get_score(user) > get_score(parent):
# change parent
user.parent = parent.parent
user.save()
# change parent's parent to current profile
parent.parent = user
parent.save()
verify_parents(parent)
In my mind this should work, if a user has a parent, check to see if the user got more points than its parent, if so, set the users parent to be the parents parent, and set the parents parent to be the user, and then they have switched places. And after that, call the same function with the parent as a target so that it can check it self, and then continue up the ladder.
But this doesnt always work, in some cases people aren't bumbed to the right position of some reason.
Edit:
When one users steps up or down a step in the ladder, it's childs move with him so they still relate to the same parent, unless they to get more points and step up. So it should be unecessary to anything with the parents shouldn't it?