1

Is there a common way for ranking system (4 different ranks) in a smart contract? The ranking of a player depends on his ETH spent. The more ETH spent, the higher the rank. This means a player can downrank at any time (through a purchase of another player). Recalculating after each purchase is too gas intensive I guess. What else can I do to solve this?

My only solution is just changing the rankings of that players, that downranked and upranked. But how shall the players be stored? As map or list? Linked-list does not seem to be correct in here.

EDIT: I think I have mastered it out. Each rank gets a threshold value. If a player makes a transaction and reaches the threshold, he ranks up. Then he has to figure out if some other players have deranked, by just checking the lowest players in each rank. This presupposes: Players must be stored in one rank. There must be 4 ranks (maps) each being a linked list. Why linked lists? because we cannot order the list physically. Then the player starts to check players balance at the bottom of the rank. If that player is still over the threshold, no player has deranked, including the player we have already checked. Otherwise the player above this player has to be checked and so on... Every player that deranks is being deleted in the current rank and being added in a rank below. Then this steps moves on until the last ranks is reached.

2

I feel I would be doing you a disservice if I didn't turn your attention to the possibility that it might be possible to externalize the sort order concern. It's worth thinking about because the idea of four indexes strikes me as more complexity than we normally want at the contract level.

Have a look at this: https://blog.b9lab.com/the-joy-of-minimalism-in-smart-contract-design-2303010c8b09

If you do need to order the lists, then you would add the pointers to each entity and index.

struct PlayerStruct {
  some Metadata,
  uint indexABefore,
  uint indexAAfter,
  uint indexBbefore,
  uint indexBAfter, 
  uint indexCBefore,
  uint indexCafter,
  uint indexDBefore,
  uint indexDAfter
}

or more condensed ...

struct PlayerStruct {
  some Metadata, 
  uint[4][2] pointers
}

Hope it helps.

  • Thank you for your answer. Unfortunately this is not what I am looking for. In my opinion it does not matter outsourcing the ranking system or not. except reducing smart contract complexity. The question is how to realize the ranking of players. Players can uprank if they buy, which implies that other players might downrank. As I said before there should be a total of 4 ranks. So every player always has only one of 4 ranks. – unheal1337 Aug 27 '18 at 10:26
2

EDIT: I think I have mastered it out. Each rank gets a threshold value. If a player makes a transaction and reaches the threshold, he ranks up. Then he has to figure out if some other players have deranked, by just checking the lowest players in each rank. This presupposes: Players must be stored in one rank. There must be 4 ranks (maps) each being a linked list. Why linked lists? because we cannot order the list physically. Then the player starts to check players balance at the bottom of the rank. If that player is still over the threshold, no player has deranked, including the player we have already checked. Otherwise the player above this player has to be checked and so on... Every player that deranks is being deleted in the current rank and being added in a rank below. Then this steps moves on until the last ranks is reached.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.