Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player leaderboard position does not consider ties #83

Open
cetteup opened this issue Dec 18, 2024 · 0 comments
Open

Player leaderboard position does not consider ties #83

cetteup opened this issue Dec 18, 2024 · 0 comments

Comments

@cetteup
Copy link

cetteup commented Dec 18, 2024

It is possible that two players have e.g. the same overall score, meaning they tie for a leaderboard position. For the leaderboard itself, that tie is broken by additionally sorting by name.

$query = "SELECT id, name, rank_id, country, time, score FROM player WHERE score > 0
ORDER BY score DESC, name DESC LIMIT " . $min . ", " . $max;

However, the tiebreaker is not applied when determining a player's position on the leaderboard directly.

$query = "SELECT COUNT(id) FROM player WHERE score > %d";

This mismatch results in a potentially incorrect and non-unique leaderboard position being returned for the player, since every player with the same score will be placed at the same position by the 2nd query.

A quick example. The actual leaderboard might be (name is sorted DESC to break ties):

Pos Nick Score
1 alpha 1000
2 charlie 900
3 bravo 900

Requesting the positions of bravo or charlie will return 2, since only alpha has a greater score.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant