python - How to solve this complex recursive problem, pyramid point system -


I am trying to program pyramid like a score system for an ARG game and came up with a problem. When users come into the game, they start a new "pyramid", but if a player starts playing with a referrer code from another player, then he becomes the child of this user and then raises the ladder. .

There is no point calculation here, I have acquired this right with some good help from the people, but if a user becomes more a point that he is a guardian, then he should turn the places into a ladder Should give. That's because a user becomes a parent of their parents and so on.

Python code does not work right now, and I really do not know why. Def valid_perient (user): "" "This is a recursive function that checks to see if any parent should collide because their parents Get more points. " "Get_score" import from Rottenetter.accounts.models try get_score: excluding parent = user.parent: return incorrect: # if this player is more than its parent, then get_score (user) & gt; Get_score (parent): # change parent user.parent = parent.parent user.save () # Change parent parent to current profile parent.parent = user parent.save () verify_parents (parent) < / Code>

This should work in my mind, if the user has a parent, check to see that the user gets more points than his parents, if If so, then set parents to become parents, and parents Set the parents of the user, and then they have changed the place. And after that, call a goal as a goal with the parents so that they can see it themselves, and then continue the ladder.

But it does not always work, in some cases people are not tied in the right position for some reason.

Edit:

When a user takes a step on the ladder or takes it down, the children go with it, so they are still related to the same parent. So that they should be unnecessary to get more marks and take steps to do so with the parents?

I think your problem may be that you have children of profile (S) are not set up right now, because now they are not guardian as their parents, as long as parents of their children can not be in your system (Which does not believe me in this case)

Alternatively (or possibly with the previous), you can simply type parent = profile.parent.get_profile () parent = profile.parent >.

Edit: And I see that you actually switched some of that other form, though user instead of profile .

However, because each user can have multiple children (as you have said in a comment on any other answer), you want to keep track of each user's child within the user's object Something like this ...

  Parents = Users Original user.parent = parent.parent parent.parent = User child = user. Children for children in child: child.parent = parent user. Children = Parent.Children.Children for children in children: If child is a user: child = parent child.parent = User parent.children = user.parent.children Children for child: If child is parent: child = User  

It probably needs referrals, though, and I can remember something.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -