question

Kim Strasser avatar image
Kim Strasser asked

How can I determine the winner in a leaderboard?

I created a leaderboard for racing game. The lowest time should be on top in the leaderboard. I multiply the values with -1 in the client application and after that I submit the values to the leaderboard. And when I call GetLeaderboardRequest() in the client application to receive the leaderboard values from PlayFab, then I multiply again with -1 to get the correct value.

In this example, 4 different players had the same time 5. But the problem is, when I use "entry.Position + 1;", then I don't know who was the first of the 4 players who submitted his time in the leaderboard.

 foreach (var entry in result.Result.Leaderboard)
 {
  // Print regular leaderboard entry information
  Console.WriteLine($"{entry.Position + 1} {entry.PlayFabId} {entry.StatValue * -1}");
 }

Is it possible to find out who was the first player that submitted a time if more than one player has the same time in a leaderboard? In this case, I could determine the winner in a leaderboard.

If it is not possible, then I will sort the received PlayFab leaderboard list in the client application like in this example, but in this case I have more than one winner in the leaderboard.

For example:

Winner: PlayerA, PlayerB, PlayerC, PlayerD : -5

Second place: PlayerZ : -6

Third place: PlayerH, PlayerU : -8

I found out that ranking in a leaderboard is not based on time if more than one player has the same value in a leaderboard, because I did the following test(in chronological order):

B7B157BCE72CA94 submitted the time -5.

4870F0A53990136E submitted the time -5.

BEFC1AFD845D8567 submitted the time -5.

1F93F4835D268BC0 submitted the time -5.

But when I call GetLeaderboardRequest(), then the order looks like this:

{"PlayerId":"4870F0A53990136E","Value":-5}
{"PlayerId":"1F93F4835D268BC0","Value":-5}
{"PlayerId":"B7B157BCE72CA94","Value":-5}
{"PlayerId":"BEFC1AFD845D8567","Value":-5}

Normally, B7B157BCE72CA94 should be on the first place in the leaderboard because he submitted his time earlier to the leaderboard but PlayFab added 4870F0A53990136E on the first place.

Is it not possible to determine only one winner if more than one player has the same value in the leaderboard?

Leaderboards and Statistics
10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

Hi Kim, from my point of view, I think Leaderboards shouldn’t be used in this way. Leaderborads are for tournaments to increase engagement within your game. For instance, in your racing game, every player who has reached a new score, he can choose to submit his score to PlayFab and later Leaderboards will update the rank at regular intervals (you can set it manually). Every player in your game can see the leaderboard so they can play harder to get a high rank. Therefore, I would suggest you implement this win-lose game logic either within your client or the server which you are using to synchronize game states. For example, choose a master client to judge who has won the game. You could give a try, any issues let us know:)

5 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.

Kim Strasser avatar image Kim Strasser commented ·

The problem is that I can not use prize tables to automatically grant virtual currency or items if multiple players have the same time. For example, if I use prize tables and only grant a price to the first place in the leaderboard, then only player 4870F0A53990136E would receive a price and the other 3 players wouldn't receive a price even though they have the same time as player 4870F0A53990136E.

I think I will only grant virtual currency and items manually to players after a daily/weekly leaderboard is reset, because then I can decide myself who gets a price and who doesn't.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Kim Strasser commented ·

Hi Kim, I don’t follow, what does your game look like? Is it like a multiplayer game where several players play together or it’s like a single player game where one player race in a map and post his racing result to Leaderboards and get award according to his rank? Can you describe more about it so we can provide you with proper suggestions.

0 Likes 0 ·
Kim Strasser avatar image Kim Strasser Citrus Yan commented ·

It's a single player game where one player race in a map and after he finished the map the racing result(his time) is posted to the leaderboard of this map. I will have one leaderboard for each map and I want to create weekly tournaments. The first, second and third rank in a leaderboard receives a prizes(virtual currency, items). I measure the time with milliseconds, for example 02:19.417. But I'm sure that there will be sometimes several players with the same time in the leaderboard.

0 Likes 0 ·
Show more comments
Seth Du avatar image Seth Du ♦ Kim Strasser commented ·

I believe what you have required is not natively supported by PlayFab and Leaderboard cannot handle your scenario. The work around solution is to integrate with SnowFlake or other external database service where you can monitor and manage the Playstream events and do advanced queries.

0 Likes 0 ·
Good Guy avatar image
Good Guy answered

Citrus Yan can you fix the "Roadmap" link you posted?

1 comment
10 |1200

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

Seth Du avatar image Seth Du ♦ commented ·

It has been fixed.

0 Likes 0 ·

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.