This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-27 15:08:01

Tbtemplex97
Scratcher
Registered: 2011-11-12
Posts: 100+

Rank Formulae

I am Looking a Rank formula which takes your xp and turns it into a level
The max lvl is 40

I want the formula to look at a list and the #1 person with the most xp will be lvl 40 and people below will be less, there can only be one lvl 40

The list will be ordered from most xp to least

Example (this is what the list will look like):

XP:
139102
129101
110110
100000
99430
28382
23980
2308
232
12
4
1


Online Status: http://blocks.scratchr.org/API.php?action=onlineStatus&user=Tbtemplex97
Darkspace Coming Soon!, Try the Singleplayer Demo

Offline

 

#2 2012-12-29 22:13:03

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Rank Formulae

Do you want the lowest person to be rank one, and the highest to be rank forty, like grading on a curve?  Or do you want it to be like the top is lvl 40, and then 39, and so on?  It makes a pretty big difference.


http://i49.tinypic.com/rk60py.png

Offline

 

#3 2012-12-29 22:29:09

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Rank Formulae

The requirement that there only be one Lvl 40 complicates things.  What do you want done if there is a tie in the experience points of the top two people?

Ignoring that issue, for the moment, I guess you could simply locate the top exp score and define that as lvl 40, then just divide the remaining range of values evenly into the other 39 levels...


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#4 2012-12-30 04:10:57

JH1010
Scratcher
Registered: 2012-05-31
Posts: 1000+

Re: Rank Formulae

I think you mean something like this:

lv1:0xp
lv2:1xp
lv3:2xp
lv4:4xp
lv5:8xp
lv6:16xp
lv7:32xp
lv8:64xp
lv9:128xp
lv10:256xp
lv11:512xp
lv12:1024xp
lv13:2048xp
lv14:4096xp
lv15:8192xp
lv16:16384xp
lv17:32768xp
lv18:65536xp
lv19:131072xp
lv20:262144xp
lv21:524288xp
lv22:1048576xp
lv23:2097152xp
lv24:4194304xp
lv25:8388608xp
lv26:16777216xp
lv27:33554432xp
lv28:67108864xp
lv29:134217728xp
lv30:268435456xp
lv31:536870912xp
lv32:1073741824xp
lv33:2147483648xp
lv34:4294967296xp
lv35:8589934592xp
lv36:17179869184xp
lv37:34359738368xp
lv38:68714476736xp
lv39:17343943472xp
lv40:274877906944xp

It doubles every time with this.

Offline

 

#5 2012-12-30 11:45:48

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Rank Formulae

Alternatively, take the top XP as level 40 and simply define all other levels this way.

set [maxXP v] to [139102] //define constants. You may want the first item in a list.
set [levels v] to [40]
set [xp/level v] to ((maxXP) / (levels))

when I receive [getLevel v] //to get level of a certain xp
say (((xp) - ((xp) mod (xp/level))) / (xp/level))
The mod(ulo) operation gives us the remainder of dividing the XP by the XP/level, and we substract that to the XP so we can get a whole number. The result of this is divided by the XP/level and we get our result.

Pseudocode, if it's any easier to understand:

Code:

maxXP = 139102
levels = 40
xp_per_level = max_xp / levels

function getLevel(xp)
    return (xp - (xp % xp_per_level)) / xp_per_level
end

This formula gives a linear progress curve - you'll always need the same amount of XP to progress further.

EDIT: And if the condition of two people with exactly the same XP is met, as Paddle2See points out, both will be lv40.  smile

Last edited by technoguyx (2012-12-30 11:47:34)


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#6 2012-12-30 16:19:22

Tbtemplex97
Scratcher
Registered: 2011-11-12
Posts: 100+

Re: Rank Formulae

technoguyx wrote:

Alternatively, take the top XP as level 40 and simply define all other levels this way.

set [maxXP v] to [139102] //define constants. You may want the first item in a list.
set [levels v] to [40]
set [xp/level v] to ((maxXP) / (levels))

when I receive [getLevel v] //to get level of a certain xp
say (((xp) - ((xp) mod (xp/level))) / (xp/level))
The mod(ulo) operation gives us the remainder of dividing the XP by the XP/level, and we substract that to the XP so we can get a whole number. The result of this is divided by the XP/level and we get our result.

Pseudocode, if it's any easier to understand:

Code:

maxXP = 139102
levels = 40
xp_per_level = max_xp / levels

function getLevel(xp)
    return (xp - (xp % xp_per_level)) / xp_per_level
end

This formula gives a linear progress curve - you'll always need the same amount of XP to progress further.

EDIT: And if the condition of two people with exactly the same XP is met, as Paddle2See points out, both will be lv40.  smile

Thanks very much. that works fine, TBH ive never known what mod does before so i havent considered using it

I need this script as i am making a leaderboard system for a game but i also what a rank system for that game


Online Status: http://blocks.scratchr.org/API.php?action=onlineStatus&user=Tbtemplex97
Darkspace Coming Soon!, Try the Singleplayer Demo

Offline

 

Board footer