question

eric@begoodi.fr avatar image
eric@begoodi.fr asked

Leaderboard ranking

When 2 players have the same statistics, their position is not the same.

Example :
   Bob - 5 points
   Bill - 3 points
   John - 3 points
   Sam - 2 points

Their position should be respectively 1, 2, 2 and 4 as Bill and John have the same values, but it returns 1, 2, 3, 4.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

[Update] To be clear, leaderboard response are 0-based, so the positions are 0..n - corrected below.

Actually, no. Leaderboards are 0..n ordered listings of players, with their position being determined by score. In the case of a tie, there's still an order for how the players appear in the list, but they cannot share a position. The position should be consistent each time you query, however.

If you have a look at services like PSN and Xbox, you'll see that their leaderboards also function this way.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

andrestallos avatar image andrestallos commented ·

Hello! I have a follow up question closely related to this topic. In that situation where two or more players have the same score in the leaderboard, is there a way to predict what will determine their order? (eg. timing of their last leaderboard entry, alphabetical order of their name, ascending playfabId...)

We use leaderboards and some players have asked what happens when there's a tie - which, based on this post, means that one might get a prize and the other wouldn't. We'd like to at least be able to tell them who would come out on top in case of a tie.

Please let me know if I should open a separate post instead for this.

Thank you!

0 Likes 0 ·
brendan avatar image brendan andrestallos commented ·

In the legacy leaderboard model, no. The updated leaderboard system we're working on rolling out will have them deterministically in order (they'll be ordered by the time at which they posted the score).

0 Likes 0 ·
Alamin mohammed avatar image Alamin mohammed brendan commented ·

Hi, I was wondering if this is being rolled out soon. I am testing the playfab leaderboard and in cases of a tied score, it seems to place the latest user at the top. (ideally I would prefer the person who got the score first to remain first)

Thanks

0 Likes 0 ·
Wayne Karo avatar image
Wayne Karo answered

Actually, maybe yes.  There are leaderboards that rank ties with the same positions.  Here is an example I found without much searching on the internet.  Obviously there is still a order to which person comes first in the tie, such as the first person to finish a match.  I think what the OP may be suggesting is that there needs to be 2 pieces of data: the rank position and the sort order position.  It would be friendly for the GetLeaderboard call to pass both back, but they can also write their own function to calculate rank position since the score data is already being returned.

I think it is pretty common to display leaderboards like the OP wants.  Our studio has made games that display leaderboards in this way in the past.  I would vote for including it in PlayFab.

 

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Exactly - the order players appear in the list is their position, which is exactly what our leaderboards do, as well.

The main issue with the proposal is around how to determine when players have tied scores. I know that sounds trivial, but consider that both scenarios of storing this information with the leaderboard and calculating it on the fly are error-prone:

a) If you tried to store the value with the leaderboard entry, that would require iterating through the following entries to find all duplicate scores and updating them. Scores updates while this is done would introduce errors.

b) If you iterated backwards to find all matching scores, in order to return an indication of the "calculated position", changes made to the leaderboard while the code is doing that would again introduce errors.

In both cases, this becomes especially bad when you take into account titles with very narrow ranges of scores, causing many players to have matching entries. And even without that, we do have to design for titles having millions of users (and so, millions of entries), making this much more likely to occur.

Now, the example found is for the Masters Tournament, rather than a video game. Personally, I have not seen this used in the video games I commonly play, but I wouldn't be surprised if some did what Wayne suggests and calculated the display based upon matching scores. That would really be the best way to go. It is true that players at the top and bottom of the displayed list may not have the correct indication of position if they're tied with people who are above/below the loaded values, but the error there is lower risk than the errors mentioned above.

That said, @Wayne, if you have a proposed design for a better solution which would avoid the errors I mentioned, feel free to let us know and I can talk through this with the engineering team.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Wayne Karo avatar image
Wayne Karo answered

I don't have a solution at this time.  Leaderboards can be challenging to engineer at large scale.  In the past, we usually tried to bin down to small set sizes so post-processing the data to get it to display the way you like is easier.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

eric@begoodi.fr avatar image
eric@begoodi.fr answered

Brendan, I don't know what you are using as your backend DB, but this ranking is sometimes possible directly in the query (SQL Server), or when it's not, it's still possible like in MySql :

SET @prev_value = NULL;
SET @rank_count = 0;
SELECT id, rank_column, CASE
    WHEN @prev_value = rank_column THEN @rank_count
    WHEN @prev_value := rank_column THEN @rank_count := @rank_count + 1
END AS rank
FROM rank_table
ORDER BY rank_column

You probably have a NoSql DB and I don't know them very well, but perhaps there is builtin procedures that does the job ?

 

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

That query works, if you're reading the full table, but in the case of a large-scale database, you have to skip to the starting point for the read. That then means you have the same problem I described above, when doing the calculation locally - you can't tell what the first player in the list should be in the display, without reading back through the scores "above" the top one in the listing.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.