The rule at work here is that users can be awarded badges for a streak of 10, 20, and 30. But the user can't be awarded multiple badges for the same streak. I'm tracking consec wins in the user model.
For example, if the user hits a 10-streak, the user is awarded a 10-streak badge. If the user is on a 20-streak, he/she receives a 20-streak badge. If the user is on a 30-game win streak, the user is awarded a 30-streak badge. The user shouldn't be awarded three 10-streak badges -- only one 10-streak, one 20-streak, and one 30-streak.
Further, if the user reaches a 40-win streak, then the user should be awarded a 10-streak badge. If the user hits 50, then he/she should be awarded a 20-streak badge. If the user hits 60, the user should be award a 30-streak badge. If the user hits 70, the user should be awarded a 10-streak. I think you get the pattern here. A 30-streak trophy is the max a user can get. But the user can be on an infinite winning streak.
def check_win_streak(streak)
badge = 10
while badge < BADGE::MAX_STREAK_BADGE_SIZE do # MAX_STREAK_BADGE_SIZE = 30
if streak < badge then
break
end
if (streak % badge == 0) then
award_streak_badge(badge)
end
badge += 10
end
end