Skip to content

Commit

Permalink
fix: rank Flagle leaderboard entries the same if scores are the same
Browse files Browse the repository at this point in the history
  • Loading branch information
maddiemort committed Oct 6, 2024
1 parent 1d0f51b commit 794f7f9
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/game/flagle/leaderboards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,27 @@ impl From<Daily> for CreateEmbed {
.field("board", format!("{}", leaderboard.day), true);

let mut description = String::new();

let mut last_score = usize::MAX;
let mut duplicates = 0;

for (i, entry) in leaderboard.entries.into_iter().enumerate() {
if last_score == entry.score {
duplicates += 1;
} else {
duplicates = 0;
};

writeln!(
&mut description,
"{}. {} ({} pts)",
i + 1,
i + 1 - duplicates,
Mention::User(entry.user_id),
entry.score,
)
.expect("should be able to write into String");

last_score = entry.score;
}

embed = embed
Expand Down Expand Up @@ -232,15 +244,27 @@ impl From<AllTime> for CreateEmbed {
);

let mut description = String::new();

let mut last_score = usize::MAX;
let mut duplicates = 0;

for (i, (user_id, score)) in leaderboard.scores_listing.into_iter().enumerate() {
if last_score == score {
duplicates += 1;
} else {
duplicates = 0;
};

writeln!(
&mut description,
"{}. {}: {}",
i + 1,
i + 1 - duplicates,
Mention::User(user_id),
score,
)
.expect("should be able to write into String");

last_score = score;
}

embed = embed
Expand Down

0 comments on commit 794f7f9

Please sign in to comment.