views:

84

answers:

3

I trying find a simple python-based algorithmic ranking system.

Here's the scenario:

There will be 30 levels, level 1 starts at 0 points. 2000 points are required to achieve level 30.

More points will be required as the levels progress.

For example, to go from level 1 to 2 might take 3 points. Level 2 to 3 might take 5 additional points. Level 29-30 might take 1200 additional points.

Since the score will be calculated on the fly, I also need a way to determine which level the player is at. For example, what level is a person with 358 points?

I could set the points manually but the 2000 point cap will fluctuate from day to day so that is not an idealistic option.

I was thinking something similar to Google's Pagerank (1-10) where it's easy to get from 0 to 4 but 9-10 is a very hard accomplishment.

Any simple snippets or tippets?

Thanks

+2  A: 

The usual solution is to use a logarithmic scale. If you use log base 2, then each level needs twice as many points. If you use a log base 10, each level needs 10 times the points. This way, you can "bend" the curve. See the Wikipedia page for the math.

Aaron Digulla
@Aaron, thanks for the tip. My attempted crash course into logarithms almost killed me, just kidding. It refreshed my memory and led me into the right direction. Thanks.
Louis
A: 

Well, here's a simple answer as far as how to look-up the level easily. Just make a sorted list of the number of points to reach each level ( - 1 depending on your bsearch) and do a binary search. The place that is pointed at for an insertion in the list will tell you the level. You can easily change this level list each day or whenever you update. You could even do a linear search since you only have 30 levels and it shouldn't really be much of a difference in performance.

Justin Peel
+2  A: 

Use a logarithmic scale. If you want a code example:

base = 2 # change to change the rate at which you go through the levels
levels = 30
finalPoints = 2000
scale = levels/math.log(finalPoints, base)
level = math.floor(scale*math.log(points, base))
Nick Fortescue
@Nick, nice example. My headache suddenly went away. Thank you!
Louis