CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2003
    Location
    South Africa
    Posts
    45

    Algorithm for awarding prizes on a leaderboard

    Hi,

    If you have a prize pool (say 1,000 points), and a leaderboard like:

    Rank / Name
    1 / Dan
    2 / Rachel
    3 / Max
    4 / Chloe
    5 / Grant
    etc.

    Is there an algorithm where you can input prize pool, rank, and maybe the number of people, and it will give you the number of points (or a %) for each rank. The person ranked #1 would get like 25% of the prize pool, and each person below would get less and less until the full prize pool is paid out.

    Possible? Ideas?

    Thanks.

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: Algorithm for awarding prizes on a leaderboard

    Quote Originally Posted by DodgerLD View Post
    less and less
    You first need to define what "less and less" actually means. Say you express it in relation to what the first rank gets. As an example say the first rank gets 1, the second rank gets half of that namely 1/2 and the third 1/3 of what the first got and then 1/4 and finally 1/5.

    You then translate this to "portions of the whole" by first calculating the whole which is the sum of the parts, like

    S = 1 + 1/2 + 1/3 + 1/4 + 1/5

    You then can easily calculate what portion of this whole each rank gets. The first gets 1/S, the second gets (1/2)/S, the third (1/3)/S, etcetera.

    Finally if you multiply these portions with 100 you get the percentage each portion constitutes of the whole. Or you can multiply the portions with the prize pool to directly get the number of points each rank gets.

    If you feel the lower ranks get too much you can use some other distribution scheme you consider fairer. Say for example each rank should only get half of what the next better rank got you end up with this distribution: 1, 1/2, 1/4, 1/8 and 1/16. But the principle of how to calculate portions of a whole remains the same.
    Last edited by nuzzle; December 21st, 2010 at 02:23 AM.

  3. #3
    Join Date
    Jan 2003
    Location
    South Africa
    Posts
    45

    Re: Algorithm for awarding prizes on a leaderboard

    Hi nuzzle,

    I think this is the same idea that I got from someone on IRC. I converted his formula to Excel for testing:

    ((1 - p) / (1 - p ^ n) * p ^ (r - 1)) * l

    p = a value between 0 and 1 which defines the distribution.
    n = number of players
    r = rank
    l = prize pool

    Thanks for your help!

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Algorithm for awarding prizes on a leaderboard

    Or, you can do it like we do in one of the games I play. 1st = 100%; the rest = 0%. Really easy!

    Viggy

  5. #5
    Join Date
    Jan 2003
    Location
    South Africa
    Posts
    45

    Re: Algorithm for awarding prizes on a leaderboard

    I wish.

  6. #6
    Join Date
    May 2009
    Posts
    2,413

    Re: Algorithm for awarding prizes on a leaderboard

    Quote Originally Posted by DodgerLD View Post
    ((1 - p) / (1 - p ^ n) * p ^ (r - 1)) * l
    This formula is based on that you express the portions as a geometric series. One of the example series I gave,

    1, 1/2, 1/4, 1/8, 1/16, .......

    is an example of a geometric series. It can alternatively be written as,

    (1/2)^0, (1/2)^1, (1/2)^2, (1/2)^3, (1/2)^4, .......

    which means p of your formula has been chosen to be 1/2.

    Generally the sum of a geometric series can be written like,

    S = (1 - p^n) / (1 - p)

    which you recognize in your formula above. In my example series n is 5.

    And the p^(r - 1) part of your formula just selects the proper term in the series for each rank number r.

    So your formula calculates the rank portions (distributed according to a geometric series) indeed.

  7. #7
    Join Date
    Jan 2003
    Location
    South Africa
    Posts
    45

    Re: Algorithm for awarding prizes on a leaderboard

    Sweet. Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured